
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Description:       :GuoYuanKeJi
@Date     :2022/07/12 09:38:09
@Author      :Yang
@version      :1.0
'''
from tkinter.filedialog import askdirectory 
from tkinter.filedialog import askdirectory as tkfa
from tkinter.filedialog import askopenfilename as tkfan
from tkinter import scrolledtext
import Sentinel2DownLoadTool as sdt
import GetSentinel2Raster as gsr
import CheckSentinel as cs
import tkinter as tk
import tkinter.ttk
import tkinter.font
from threading import Thread
from calendar import  monthrange as rangeM
import datetime
import paramiko
import json
import os


def sftp_test_folder(hostname,port,username,password,folders):
    client=paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
    client.connect(hostname=hostname,port=port,username=username,password=password,timeout=15)
    sftp = client.open_sftp()
    for folder in folders:
        try:sftp.chdir(folder) 
        except:
            sftp.close()
            client.close()
            return f"{folder}：远程目录不存在！"
    sftp.close()
    client.close()
    return '\n'.join(folders)+"\n远程目录存在！"
    

def sftp_test_file(hostname,port,username,password,paths):
    client=paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
    client.connect(hostname=hostname,port=port,username=username,password=password,timeout=15)
    sftp = client.open_sftp()
    for path in paths:
        try:sftp.stat(path)   
        except:
            sftp.close()
            client.close()
            return f"{path}：远程文件不存在！"
    sftp.close()
    client.close()
    return '\n'.join(paths)+"\n远程文件存在！"


def ssh_test(hostname,port,username,password):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
    try:
        ssh.connect(hostname=hostname,port=port,username=username,password=password,timeout=15)
        result = f'{hostname}：远程连接成功！'
        ssh.close()
    except:
        result = f'{hostname}：远程连接失败！'
        ssh.close()
    return result


# 载入初始化配置文件
def load_configfile(file_path=r"./SentinelToolBoxConfig.json"):
    if not os.path.exists(file_path): 
        tileds = {
            "浙江省": [
                "50RQV",
                "50RPU",
                "50RQU",
                "50RNT",
                "50RPT",
                "50RQT",
                "50RPS",
                "50RQS",
                "50RPR",
                "50RQR",
                "51RTQ",
                "51RUQ",
                "51RTP",
                "51RUP",
                "51RVP",
                "51RTN",
                "51RUN",
                "51RVN",
                "51RTM",
                "51RUM",
                "51RTL",
                "51RUL"
            ],
            "云南省": [
                "48QTM",
                "48QUM",
                "48QVM",
                "48QWM",
                "48QXM",
                "48QTL",
                "48QUL",
                "48QVL",
                "48QWL",
                "48QXL",
                "48QTK",
                "48QUK",
                "48RUS",
                "48RVS",
                "48RWS",
                "48RTR",
                "48RUR",
                "48RVR",
                "48RWR",
                "48RTQ",
                "48RUQ",
                "48RVQ",
                "48RTP",
                "48RUP",
                "48RVP",
                "48RTN",
                "48RUN",
                "48RVN",
                "48RWN",
                "47QLG",
                "47QMG",
                "47QNG",
                "47QPG",
                "47QQG",
                "47QRG",
                "47QMF",
                "47QNF",
                "47QPF",
                "47QQF",
                "47QRF",
                "47QNE",
                "47QPE",
                "47QQE",
                "47QRE",
                "47QPD",
                "47QQD",
                "47RMN",
                "47RNN",
                "47RMM",
                "47RNM",
                "47RPM",
                "47RML",
                "47RNL",
                "47RPL",
                "47RQL",
                "47RMK",
                "47RNK",
                "47RPK",
                "47RQK",
                "47RMJ",
                "47RNJ",
                "47RPJ",
                "47RQJ",
                "47RRJ",
                "47RLH",
                "47RMH",
                "47RNH",
                "47RPH",
                "47RQH",
                "47RRH"
            ],
            "新疆": [
                "43SCD",
                "43SDD",
                "43SED",
                "43SFD",
                "43SGD",
                "43SCC",
                "43SDC",
                "43SEC",
                "43SFC",
                "43SGC",
                "43SDB",
                "43SEB",
                "43SFB",
                "43SGB",
                "43SDA",
                "43SEA",
                "43SFA",
                "43SGA",
                "43SEV",
                "43SFV",
                "43SGV",
                "43TEF",
                "43TFF",
                "43TGF",
                "43TDE",
                "43TEE",
                "43TFE",
                "43TGE",
                "44SKJ",
                "44SLJ",
                "44SMJ",
                "44SNJ",
                "44SPJ",
                "44SQJ",
                "44SKH",
                "44SLH",
                "44SMH",
                "44SNH",
                "44SPH",
                "44SQH",
                "44SKG",
                "44SLG",
                "44SMG",
                "44SNG",
                "44SPG",
                "44SQG",
                "44SKF",
                "44SLF",
                "44SMF",
                "44SNF",
                "44SPF",
                "44SQF",
                "44SKE",
                "44SLE",
                "44SME",
                "44SNE",
                "44SPE",
                "44SQE",
                "44SKD",
                "44SLD",
                "44SMD",
                "44SND",
                "44TPT",
                "44TQT",
                "44TPS",
                "44TQS",
                "44TMR",
                "44TNR",
                "44TPR",
                "44TQR",
                "44TMQ",
                "44TNQ",
                "44TPQ",
                "44TQQ",
                "44TMP",
                "44TNP",
                "44TPP",
                "44TQP",
                "44TMN",
                "44TNN",
                "44TPN",
                "44TQN",
                "44TLM",
                "44TMM",
                "44TNM",
                "44TPM",
                "44TQM",
                "44TKL",
                "44TLL",
                "44TML",
                "44TNL",
                "44TPL",
                "44TQL",
                "44TKK",
                "44TLK",
                "44TMK",
                "44TNK",
                "44TPK",
                "44TQK",
                "45STD",
                "45SUD",
                "45SVD",
                "45SWD",
                "45SXD",
                "45SYD",
                "45STC",
                "45SUC",
                "45SVC",
                "45SWC",
                "45SXC",
                "45SYC",
                "45STB",
                "45SUB",
                "45SVB",
                "45SWB",
                "45SXB",
                "45SYB",
                "45STA",
                "45SUA",
                "45SVA",
                "45SWA",
                "45SXA",
                "45SYA",
                "45STV",
                "45SUV",
                "45SVV",
                "45SYV",
                "45TUN",
                "45TVN",
                "45TWN",
                "45TXN",
                "45TYN",
                "45TUM",
                "45TVM",
                "45TWM",
                "45TXM",
                "45TYM",
                "45TUL",
                "45TVL",
                "45TWL",
                "45TXL",
                "45TYL",
                "45TUK",
                "45TVK",
                "45TWK",
                "45TXK",
                "45TYK",
                "45TUJ",
                "45TVJ",
                "45TWJ",
                "45TXJ",
                "45TYJ",
                "45TUH",
                "45TVH",
                "45TWH",
                "45TXH",
                "45TYH",
                "45TUG",
                "45TVG",
                "45TWG",
                "45TXG",
                "45TYG",
                "45TTF",
                "45TUF",
                "45TVF",
                "45TWF",
                "45TXF",
                "45TYF",
                "45TTE",
                "45TUE",
                "45TVE",
                "45TWE",
                "45TXE",
                "45TYE",
                "45UVQ",
                "45UWQ",
                "45UUP",
                "45UVP",
                "45UWP",
                "45UXP",
                "46SBJ",
                "46SCJ",
                "46SDJ",
                "46SBH",
                "46SCH",
                "46SBG",
                "46SCG",
                "46SBF",
                "46SCF",
                "46SBE",
                "46SCE",
                "46TCT",
                "46TCS",
                "46TCR",
                "46TCQ",
                "46TDQ",
                "46TEQ",
                "46TFQ",
                "46TCP",
                "46TDP",
                "46TEP",
                "46TFP",
                "46TGP",
                "46TCN",
                "46TDN",
                "46TEN",
                "46TFN",
                "46TGN",
                "46TCM",
                "46TDM",
                "46TEM",
                "46TFM",
                "46TGM",
                "46TBL",
                "46TCL",
                "46TDL",
                "46TEL",
                "46TFL",
                "46TBK",
                "46TCK",
                "46TDK",
                "46TEK",
                "45TTG",
                "46TBM",
                "47TKG"
            ],
            "香港": [
                "49QGE",
                "49QHE",
                "50QKK"
            ],
            "西藏": [
                "44RKV",
                "44RLV",
                "44RMV",
                "44RNV",
                "44RPV",
                "44RQV",
                "44RMU",
                "44RNU",
                "44RPU",
                "44RQU",
                "44RPT",
                "44RQT",
                "44SME",
                "44SNE",
                "44SPE",
                "44SQE",
                "44SLD",
                "44SMD",
                "44SND",
                "44SPD",
                "44SQD",
                "44SKC",
                "44SLC",
                "44SMC",
                "44SNC",
                "44SPC",
                "44SQC",
                "44SKB",
                "44SLB",
                "44SMB",
                "44SNB",
                "44SPB",
                "44SQB",
                "44SKA",
                "44SLA",
                "44SMA",
                "44SNA",
                "44SPA",
                "44SQA",
                "45RTQ",
                "45RUQ",
                "45RVQ",
                "45RWQ",
                "45RXQ",
                "45RYQ",
                "45RTP",
                "45RUP",
                "45RVP",
                "45RWP",
                "45RXP",
                "45RYP",
                "45RTN",
                "45RUN",
                "45RVN",
                "45RWN",
                "45RXN",
                "45RYN",
                "45RTM",
                "45RUM",
                "45RVM",
                "45RWM",
                "45RXM",
                "45RYM",
                "45RUL",
                "45RVL",
                "45RWL",
                "45RXL",
                "45RYL",
                "45SVA",
                "45SWA",
                "45SXA",
                "45SYA",
                "45STV",
                "45SUV",
                "45SVV",
                "45SWV",
                "45SXV",
                "45SYV",
                "45STU",
                "45SUU",
                "45SVU",
                "45SWU",
                "45SXU",
                "45SYU",
                "45STT",
                "45SUT",
                "45SVT",
                "45SWT",
                "45SXT",
                "45SYT",
                "45STS",
                "45SUS",
                "45SVS",
                "45SWS",
                "45SXS",
                "45SYS",
                "45STR",
                "45SUR",
                "45SVR",
                "45SWR",
                "45SXR",
                "45SYR",
                "46RBV",
                "46RCV",
                "46RDV",
                "46REV",
                "46RFV",
                "46RGV",
                "46RBU",
                "46RCU",
                "46RDU",
                "46REU",
                "46RFU",
                "46RGU",
                "46RBT",
                "46RCT",
                "46RDT",
                "46RET",
                "46RFT",
                "46RGT",
                "46RBS",
                "46RCS",
                "46RDS",
                "46RES",
                "46RFS",
                "46RGS",
                "46RBR",
                "46RCR",
                "46RDR",
                "46RER",
                "46RFR",
                "46RGR",
                "46RDQ",
                "46REQ",
                "46SBC",
                "46SBB",
                "46SCB",
                "46SDB",
                "46SEB",
                "46SFB",
                "46SBA",
                "46SCA",
                "46SDA",
                "46SEA",
                "46SFA",
                "46SGA",
                "47RKQ",
                "47RLQ",
                "47RMQ",
                "47RKP",
                "47RLP",
                "47RMP",
                "47RNP",
                "47RKN",
                "47RLN",
                "47RMN",
                "47RNN",
                "47RKM",
                "47RLM",
                "47RMM",
                "47RKL",
                "47RLL",
                "47SLS",
                "47SKR",
                "47SLR",
                "47SMR"
            ],
            "台湾省": [
                "51QTG",
                "51QUG",
                "51QTF",
                "51QUF",
                "51QTE",
                "51RTH",
                "51RUH"
            ],
            "四川省": [
                "48RTV",
                "48RUV",
                "48RVV",
                "48RWV",
                "48RXV",
                "48RYV",
                "48RTU",
                "48RUU",
                "48RVU",
                "48RWU",
                "48RXU",
                "48RYU",
                "48RTT",
                "48RUT",
                "48RVT",
                "48RWT",
                "48RXT",
                "48RTS",
                "48RUS",
                "48RVS",
                "48RWS",
                "48RXS",
                "48RTR",
                "48RUR",
                "48RVR",
                "48RWR",
                "48RXR",
                "48RTQ",
                "48RUQ",
                "48RTP",
                "48STC",
                "48SUC",
                "48SVC",
                "48STB",
                "48SUB",
                "48SVB",
                "48SWB",
                "48SXB",
                "48SYB",
                "48STA",
                "48SUA",
                "48SVA",
                "48SWA",
                "48SXA",
                "48SYA",
                "49RBQ",
                "49SBR",
                "47RMQ",
                "47RNQ",
                "47RPQ",
                "47RQQ",
                "47RMP",
                "47RNP",
                "47RPP",
                "47RQP",
                "47RMN",
                "47RNN",
                "47RPN",
                "47RQN",
                "47RNM",
                "47RPM",
                "47RQM",
                "47RPL",
                "47RQL",
                "47RQK",
                "47RQJ",
                "47RRJ",
                "47SLT",
                "47SMT",
                "47SQT",
                "47SLS",
                "47SMS",
                "47SNS",
                "47SPS",
                "47SQS",
                "47SLR",
                "47SMR",
                "47SNR",
                "47SPR",
                "47SQR"
            ],
            "陕西省": [
                "48SXG",
                "48SYG",
                "48SYF",
                "48SYE",
                "48SXD",
                "48SYD",
                "48SWC",
                "48SXC",
                "48SYC",
                "48SWB",
                "48SXB",
                "48SYB",
                "48SXA",
                "48SYA",
                "49SCD",
                "49SDD",
                "49SED",
                "49SCC",
                "49SDC",
                "49SEC",
                "49SBB",
                "49SCB",
                "49SDB",
                "49SBA",
                "49SCA",
                "49SDA",
                "49SBV",
                "49SCV",
                "49SDV",
                "49SBU",
                "49SCU",
                "49SDU",
                "49SBT",
                "49SCT",
                "49SDT",
                "49SET",
                "49SBS",
                "49SCS",
                "49SDS",
                "49SES",
                "49SBR",
                "49SCR"
            ],
            "山西省": [
                "49SDD",
                "49SED",
                "49SFD",
                "49SGD",
                "49SDC",
                "49SEC",
                "49SFC",
                "49SGC",
                "49SDB",
                "49SEB",
                "49SFB",
                "49SGB",
                "49SDA",
                "49SEA",
                "49SFA",
                "49SGA",
                "49SDV",
                "49SEV",
                "49SFV",
                "49SGV",
                "49SDU",
                "49SEU",
                "49SFU",
                "49TEE",
                "49TFE",
                "49TGE",
                "50SKJ",
                "50SKG",
                "50TKL",
                "50TKK"
            ],
            "山东省": [
                "50SNH",
                "50SPH",
                "50SLG",
                "50SMG",
                "50SNG",
                "50SPG",
                "50SQG",
                "50SLF",
                "50SMF",
                "50SNF",
                "50SPF",
                "50SQF",
                "50SLE",
                "50SME",
                "50SNE",
                "50SPE",
                "50SQE",
                "50SKD",
                "50SLD",
                "50SMD",
                "50SND",
                "50SPD",
                "50SQD",
                "51STB",
                "51SUB",
                "51SVB",
                "51STA",
                "51SUA",
                "51SVA",
                "51STV"
            ],
            "青海省": [
                "48STG",
                "48STF",
                "48SUF",
                "48STE",
                "48SUE",
                "48STD",
                "48STC",
                "45SYA",
                "45SYV",
                "45SYU",
                "45SYT",
                "46SCJ",
                "46SDJ",
                "46SEJ",
                "46SFJ",
                "46SGJ",
                "46SBH",
                "46SCH",
                "46SDH",
                "46SEH",
                "46SFH",
                "46SGH",
                "46SBG",
                "46SCG",
                "46SDG",
                "46SEG",
                "46SFG",
                "46SGG",
                "46SBF",
                "46SCF",
                "46SDF",
                "46SEF",
                "46SFF",
                "46SGF",
                "46SBE",
                "46SCE",
                "46SDE",
                "46SEE",
                "46SFE",
                "46SGE",
                "46SBD",
                "46SCD",
                "46SDD",
                "46SED",
                "46SFD",
                "46SGD",
                "46SBC",
                "46SCC",
                "46SDC",
                "46SEC",
                "46SFC",
                "46SGC",
                "46SBB",
                "46SCB",
                "46SDB",
                "46SEB",
                "46SFB",
                "46SGB",
                "46SEA",
                "46SFA",
                "46SGA",
                "47RKQ",
                "47SLD",
                "47SMD",
                "47SND",
                "47SKC",
                "47SLC",
                "47SMC",
                "47SNC",
                "47SPC",
                "47SKB",
                "47SLB",
                "47SMB",
                "47SNB",
                "47SPB",
                "47SQB",
                "47SKA",
                "47SLA",
                "47SMA",
                "47SNA",
                "47SPA",
                "47SQA",
                "47SKV",
                "47SLV",
                "47SMV",
                "47SNV",
                "47SPV",
                "47SQV",
                "47SKU",
                "47SLU",
                "47SMU",
                "47SNU",
                "47SPU",
                "47SQU",
                "47SKT",
                "47SLT",
                "47SMT",
                "47SNT",
                "47SPT",
                "47SQT",
                "47SKS",
                "47SLS",
                "47SMS",
                "47SNS",
                "47SPS",
                "47SQS",
                "47SKR",
                "47SLR",
                "47SPR"
            ],
            "宁夏": [
                "48SWJ",
                "48SXJ",
                "48SWH",
                "48SXH",
                "48SYH",
                "48SVG",
                "48SWG",
                "48SXG",
                "48SYG",
                "48SVF",
                "48SWF",
                "48SXF",
                "48SWE",
                "48SXE"
            ],
            "内蒙古": [
                "48STJ",
                "48SUJ",
                "48SVJ",
                "48SWJ",
                "48SXJ",
                "48SYJ",
                "48SUH",
                "48SVH",
                "48SWH",
                "48SXH",
                "48SYH",
                "48SUG",
                "48SVG",
                "48SWG",
                "48SYG",
                "48TXN",
                "48TYN",
                "48TUM",
                "48TVM",
                "48TWM",
                "48TXM",
                "48TYM",
                "48TTL",
                "48TUL",
                "48TVL",
                "48TWL",
                "48TXL",
                "48TYL",
                "48TTK",
                "48TUK",
                "48TVK",
                "48TWK",
                "48TXK",
                "48TYK",
                "49SBD",
                "49SCD",
                "49SDD",
                "49SED",
                "49SBC",
                "49SCC",
                "49SBB",
                "49SCB",
                "49TEK",
                "49TFK",
                "49TGK",
                "49TEJ",
                "49TFJ",
                "49TGJ",
                "49TCH",
                "49TDH",
                "49TEH",
                "49TFH",
                "49TGH",
                "49TCG",
                "49TDG",
                "49TEG",
                "49TFG",
                "49TGG",
                "49TBF",
                "49TCF",
                "49TDF",
                "49TEF",
                "49TFF",
                "49TGF",
                "49TBE",
                "49TCE",
                "49TDE",
                "49TEE",
                "49TFE",
                "49TGE",
                "50TMT",
                "50TNT",
                "50TPT",
                "50TQT",
                "50TMS",
                "50TNS",
                "50TPS",
                "50TQS",
                "50TLR",
                "50TMR",
                "50TNR",
                "50TPR",
                "50TQR",
                "50TLQ",
                "50TMQ",
                "50TNQ",
                "50TPQ",
                "50TQQ",
                "50TLP",
                "50TMP",
                "50TNP",
                "50TPP",
                "50TQP",
                "50TLN",
                "50TMN",
                "50TNN",
                "50TPN",
                "50TQN",
                "50TLM",
                "50TMM",
                "50TNM",
                "50TPM",
                "50TQM",
                "50TKL",
                "50TPL",
                "50TQL",
                "50TKK",
                "50UQC",
                "50UPB",
                "50UQB",
                "50UMA",
                "50UNA",
                "50UPA",
                "50UQA",
                "50UMV",
                "50UNV",
                "50UPV",
                "50UQV",
                "50ULU",
                "50UMU",
                "50UNU",
                "50UPU",
                "50UQU",
                "51TUN",
                "51TVN",
                "51TWN",
                "51TUM",
                "51TVM",
                "51TWM",
                "51TUL",
                "51TVL",
                "51TUK",
                "51TVK",
                "51TWK",
                "51TUJ",
                "51TVJ",
                "51TWJ",
                "51TUH",
                "51TVH",
                "51TWH",
                "51TUG",
                "51UUV",
                "51UVV",
                "51UUU",
                "51UVU",
                "51UUT",
                "51UVT",
                "51UXT",
                "51UUS",
                "51UVS",
                "51UWS",
                "51UXS",
                "51UYS",
                "51UUR",
                "51UVR",
                "51UWR",
                "51UXR",
                "51UUQ",
                "51UVQ",
                "51UWQ",
                "51UXQ",
                "51UUP",
                "51UVP",
                "51UWP",
                "51UXP",
                "47SND",
                "47SPD",
                "47SQD",
                "47SPC",
                "47SQC",
                "47TLH",
                "47TMH",
                "47TNH",
                "47TPH",
                "47TQH",
                "47TLG",
                "47TMG",
                "47TNG",
                "47TPG",
                "47TQG",
                "47TLF",
                "47TMF",
                "47TNF",
                "47TPF",
                "47TQF",
                "47TNE",
                "47TPE",
                "47TQE",
                "48TTM",
                "49TBG",
                "50TKM",
                "51TTG"
            ],
            "辽宁省": [
                "50TPM",
                "50TQM",
                "50TPL",
                "50TQL",
                "50TPK",
                "50TQK",
                "51SUD",
                "51SVD",
                "51SWD",
                "51SUC",
                "51TWJ",
                "51TUH",
                "51TVH",
                "51TWH",
                "51TXH",
                "51TUG",
                "51TVG",
                "51TWG",
                "51TXG",
                "51TYG",
                "51TTF",
                "51TUF",
                "51TVF",
                "51TWF",
                "51TXF",
                "51TYF",
                "51TTE",
                "51TUE",
                "51TVE",
                "51TWE",
                "51TXE",
                "51TYE",
                "51TTG"
            ],
            "江西省": [
                "49RGN",
                "49RGM",
                "49RGL",
                "49RGK",
                "49RGJ",
                "49RHJ",
                "50RLU",
                "50RMU",
                "50RNU",
                "50RKT",
                "50RLT",
                "50RMT",
                "50RNT",
                "50RPT",
                "50RKS",
                "50RLS",
                "50RMS",
                "50RNS",
                "50RPS",
                "50RKR",
                "50RLR",
                "50RMR",
                "50RNR",
                "50RPR",
                "50RKQ",
                "50RLQ",
                "50RMQ",
                "50RNQ",
                "50RKP",
                "50RLP",
                "50RMP",
                "50RKN",
                "50RLN"
            ],
            "吉林省": [
                "51TVM",
                "51TWM",
                "51TUL",
                "51TVL",
                "51TWL",
                "51TXL",
                "51TYL",
                "51TVK",
                "51TWK",
                "51TXK",
                "51TYK",
                "51TVJ",
                "51TWJ",
                "51TXJ",
                "51TYJ",
                "51TWH",
                "51TXH",
                "51TYH",
                "51TXG",
                "51TYG",
                "51TYF",
                "52TCR",
                "52TCQ",
                "52TDQ",
                "52TCP",
                "52TDP",
                "52TEP",
                "52TFP",
                "52TCN",
                "52TDN",
                "52TEN",
                "52TFN",
                "52TCM",
                "52TDM",
                "52TEM",
                "52TFM",
                "52TBL",
                "52TCL",
                "52TDL",
                "52TBM"
            ],
            "湖南省": [
                "49RDP",
                "49REP",
                "49RGP",
                "49RCN",
                "49RDN",
                "49REN",
                "49RFN",
                "49RGN",
                "49RCM",
                "49RDM",
                "49REM",
                "49RFM",
                "49RGM",
                "49RBL",
                "49RCL",
                "49RDL",
                "49REL",
                "49RFL",
                "49RGL",
                "49RBK",
                "49RCK",
                "49RDK",
                "49REK",
                "49RFK",
                "49RGK",
                "49RCJ",
                "49RDJ",
                "49REJ",
                "49RFJ",
                "49RGJ",
                "49RHJ",
                "49RDH",
                "49REH",
                "49RFH",
                "49RGH",
                "50RKT",
                "50RKS",
                "50RKQ",
                "50RKP"
            ],
            "湖北省": [
                "49RCQ",
                "49RDQ",
                "49REQ",
                "49RFQ",
                "49RGQ",
                "49RBP",
                "49RCP",
                "49RDP",
                "49REP",
                "49RFP",
                "49RGP",
                "49RBN",
                "49RCN",
                "49RDN",
                "49REN",
                "49RFN",
                "49RGN",
                "49SCS",
                "49SDS",
                "49SES",
                "49SCR",
                "49SDR",
                "49SER",
                "49SFR",
                "49SGR",
                "50RKV",
                "50RLV",
                "50RMV",
                "50RKU",
                "50RLU",
                "50RMU",
                "50RKT",
                "50RLT",
                "50RMT"
            ],
            "黑龙江": [
                "51TVN",
                "51TWN",
                "51TXN",
                "51TYN",
                "51TVM",
                "51TWM",
                "51TXM",
                "51TYM",
                "51TWL",
                "51TXL",
                "51TYL",
                "51UUV",
                "51UVV",
                "51UWV",
                "51UUU",
                "51UVU",
                "51UWU",
                "51UXU",
                "51UYU",
                "51UVT",
                "51UWT",
                "51UXT",
                "51UYT",
                "51UVS",
                "51UWS",
                "51UXS",
                "51UYS",
                "51UXR",
                "51UYR",
                "51UXQ",
                "51UYQ",
                "51UWP",
                "51UXP",
                "51UYP",
                "52TCT",
                "52TDT",
                "52TET",
                "52TFT",
                "52TGT",
                "52TCS",
                "52TDS",
                "52TES",
                "52TFS",
                "52TGS",
                "52TCR",
                "52TDR",
                "52TER",
                "52TFR",
                "52TGR",
                "52TCQ",
                "52TDQ",
                "52TEQ",
                "52TFQ",
                "52TGQ",
                "52TCP",
                "52TDP",
                "52TEP",
                "52TFP",
                "52UCD",
                "52UCC",
                "52UCB",
                "52UCA",
                "52UDA",
                "52UCV",
                "52UDV",
                "52UEV",
                "52UFV",
                "52UCU",
                "52UDU",
                "52UEU",
                "52UFU",
                "53TLN",
                "53TMN",
                "53TLM",
                "53TMM",
                "53TLL",
                "53TML",
                "53TLK",
                "53ULP",
                "53UMP",
                "53UNP"
            ],
            "河南省": [
                "49SGA",
                "49SEV",
                "49SFV",
                "49SGV",
                "49SDU",
                "49SEU",
                "49SFU",
                "49SGU",
                "49SDT",
                "49SET",
                "49SFT",
                "49SGT",
                "49SDS",
                "49SES",
                "49SFS",
                "49SGS",
                "49SER",
                "49SFR",
                "49SGR",
                "50RKV",
                "50RLV",
                "50SKF",
                "50SLF",
                "50SKE",
                "50SLE",
                "50SME",
                "50SKD",
                "50SLD",
                "50SMD",
                "50SKC",
                "50SLC",
                "50SMC",
                "50SKB",
                "50SLB",
                "50SKA",
                "50SLA"
            ],
            "北京市": [
                "50SLJ",
                "50SMJ",
                "50TML",
                "50TNL",
                "50TLK",
                "50TMK",
                "50TNK"
            ],
            "天津市": [
                "50SMJ",
                "50SNJ",
                "50SMH",
                "50SNH",
                "50TNK"
            ],
            "海南省": [
                "49QCC",
                "49QDC",
                "49QBB",
                "49QCB",
                "49QDB",
                "49QEB",
                "49QBA",
                "49QCA",
                "49QDA"
            ],
            "贵州省": [
                "48RYT",
                "48RWS",
                "48RXS",
                "48RYS",
                "48RUR",
                "48RVR",
                "48RWR",
                "48RXR",
                "48RYR",
                "48RUQ",
                "48RVQ",
                "48RWQ",
                "48RXQ",
                "48RYQ",
                "48RVP",
                "48RWP",
                "48RXP",
                "48RYP",
                "48RZP",
                "48RVN",
                "48RWN",
                "48RXN",
                "48RYN",
                "48RZN",
                "49RBN",
                "49RBM",
                "49RCM",
                "49RBL",
                "49RCL",
                "49RBK",
                "49RCK",
                "49RBJ",
                "49RCJ",
                "49RBH"
            ],
            "广西省": [
                "48QWM",
                "48QXM",
                "48QYM",
                "48QZM",
                "48QWL",
                "48QXL",
                "48QYL",
                "48QZL",
                "48QXK",
                "48QYK",
                "48QZK",
                "48QYJ",
                "48QZJ",
                "48RXP",
                "48RYP",
                "48RVN",
                "48RWN",
                "48RXN",
                "48RYN",
                "48RZN",
                "49QBG",
                "49QCG",
                "49QDG",
                "49QEG",
                "49QBF",
                "49QCF",
                "49QDF",
                "49QEF",
                "49QBE",
                "49QCE",
                "49QDE",
                "49QBD",
                "49QCD",
                "49RDK",
                "49REK",
                "49RBJ",
                "49RCJ",
                "49RDJ",
                "49REJ",
                "49RBH",
                "49RCH",
                "49RDH",
                "49REH",
                "49RFH"
            ],
            "甘肃省": [
                "48STJ",
                "48SUJ",
                "48SVJ",
                "48STH",
                "48SUH",
                "48SVH",
                "48STG",
                "48SUG",
                "48SVG",
                "48SXG",
                "48SYG",
                "48STF",
                "48SUF",
                "48SVF",
                "48SWF",
                "48SXF",
                "48SYF",
                "48STE",
                "48SUE",
                "48SVE",
                "48SWE",
                "48SXE",
                "48SYE",
                "48STD",
                "48SUD",
                "48SVD",
                "48SWD",
                "48SXD",
                "48SYD",
                "48STC",
                "48SUC",
                "48SVC",
                "48SWC",
                "48SXC",
                "48STB",
                "48SVB",
                "48SWB",
                "49SBA",
                "49SBV",
                "46SDJ",
                "46SEJ",
                "46SFJ",
                "46SGJ",
                "46SGH",
                "46TFM",
                "46TGM",
                "46TEL",
                "46TFL",
                "46TGL",
                "46TDK",
                "46TEK",
                "46TFK",
                "46TGK",
                "47SKD",
                "47SLD",
                "47SMD",
                "47SND",
                "47SPD",
                "47SQD",
                "47SKC",
                "47SLC",
                "47SMC",
                "47SNC",
                "47SPC",
                "47SQC",
                "47SPB",
                "47SQB",
                "47SPU",
                "47SQU",
                "47SPT",
                "47SQT",
                "47SQS",
                "47TLH",
                "47TLG",
                "47TMG",
                "47TKF",
                "47TLF",
                "47TMF",
                "47TNF",
                "47TPF",
                "47TKE",
                "47TLE",
                "47TME",
                "47TNE",
                "47TPE",
                "47TKG"
            ],
            "福建省": [
                "50QMM",
                "50QNM",
                "50RPS",
                "50RMR",
                "50RNR",
                "50RPR",
                "50RQR",
                "50RMQ",
                "50RNQ",
                "50RPQ",
                "50RQQ",
                "50RLP",
                "50RMP",
                "50RNP",
                "50RPP",
                "50RQP",
                "50RLN",
                "50RMN",
                "50RNN",
                "50RPN",
                "50RQN",
                "51RTL",
                "51RTK"
            ],
            "澳门": [
                "49QGE"
            ],
            "安徽省": [
                "50RLV",
                "50RMV",
                "50RNV",
                "50RPV",
                "50RQV",
                "50RLU",
                "50RMU",
                "50RNU",
                "50RPU",
                "50RQU",
                "50RMT",
                "50RNT",
                "50RPT",
                "50SMD",
                "50SLC",
                "50SMC",
                "50SNC",
                "50SPC",
                "50SLB",
                "50SMB",
                "50SNB",
                "50SPB",
                "50SQB",
                "50SLA",
                "50SMA",
                "50SNA",
                "50SPA",
                "50SQA"
            ],
            "上海市": [
                "51RTQ",
                "51RUQ",
                "51RVQ",
                "51RUP"
            ],
            "重庆市": [
                "48RYV",
                "48RWU",
                "48RXU",
                "48RYU",
                "48RWT",
                "48RXT",
                "48RYT",
                "48RWS",
                "48RXS",
                "48RYS",
                "49RBQ",
                "49RCQ",
                "49RDQ",
                "49RBP",
                "49RCP",
                "49RBN",
                "49RCN",
                "49RBM",
                "49RCM",
                "49SBR"
            ],
            "江苏省": [
                "50RPV",
                "50RQV",
                "50SMD",
                "50SND",
                "50SPD",
                "50SQD",
                "50SMC",
                "50SNC",
                "50SPC",
                "50SQC",
                "50SNB",
                "50SPB",
                "50SQB",
                "50SPA",
                "50SQA",
                "51RTQ",
                "51RUQ",
                "51STU",
                "51STT",
                "51STS",
                "51SUS",
                "51STR",
                "51SUR"
            ],
            "广东省": [
                "49QEG",
                "49QFG",
                "49QGG",
                "49QHG",
                "49QDF",
                "49QEF",
                "49QFF",
                "49QGF",
                "49QHF",
                "49QCE",
                "49QDE",
                "49QEE",
                "49QFE",
                "49QGE",
                "49QHE",
                "49QCD",
                "49QDD",
                "49QED",
                "49QCC",
                "49QDC",
                "49RFJ",
                "49RGJ",
                "49RHJ",
                "49REH",
                "49RFH",
                "49RGH",
                "49RHH",
                "50QKM",
                "50QLM",
                "50QMM",
                "50QNM",
                "50QKL",
                "50QLL",
                "50QML",
                "50QKK",
                "50RKP",
                "50RKN",
                "50RLN",
                "50RMN"
            ],
            "河北省": [
                "49SGD",
                "49SGC",
                "49SGB",
                "49SGA",
                "49TGG",
                "49TGF",
                "49TGE",
                "50SKJ",
                "50SLJ",
                "50SMJ",
                "50SNJ",
                "50SPJ",
                "50SQJ",
                "50SKH",
                "50SLH",
                "50SMH",
                "50SNH",
                "50SKG",
                "50SLG",
                "50SMG",
                "50SNG",
                "50SKF",
                "50SLF",
                "50SLE",
                "50TNN",
                "50TLM",
                "50TMM",
                "50TNM",
                "50TPM",
                "50TKL",
                "50TLL",
                "50TML",
                "50TNL",
                "50TPL",
                "50TKK",
                "50TLK",
                "50TMK",
                "50TNK",
                "50TPK",
                "50TQK",
                "50TKM"
            ],
            "东四盟": [
        "50TLU",
        "50TMU",
        "50TNU",
        "50TPU",
        "50TQU",
        "50TMT",
        "50TNT",
        "50TPT",
        "50TQT",
        "50TQS",
        "50TPR",
        "50TQR",
        "50TPQ",
        "50TQQ",
        "50TMP",
        "50TNP",
        "50TPP",
        "50TQP",
        "50TMN",
        "50TNN",
        "50TPN",
        "50TQN",
        "50TMM",
        "50TNM",
        "50TPM",
        "50TQM",
        "50TPL",
        "50TQL",
        "50UQC",
        "50UPB",
        "50UQB",
        "50UMA",
        "50UNA",
        "50UPA",
        "50UQA",
        "50UMV",
        "50UNV",
        "50UPV",
        "50UQV",
        "50ULU",
        "50UMU",
        "50UNU",
        "50UPU",
        "50UQU",
        "51TTP",
        "51TUP",
        "51TVP",
        "51TWP",
        "51TTN",
        "51TUN",
        "51TVN",
        "51TWN",
        "51TTM",
        "51TUM",
        "51TVM",
        "51TWM",
        "51TTL",
        "51TUL",
        "51TVL",
        "51TTK",
        "51TUK",
        "51TVK",
        "51TWK",
        "51TTJ",
        "51TUJ",
        "51TVJ",
        "51TWJ",
        "51TTH",
        "51TUH",
        "51TVH",
        "51TWH",
        "51TTG",
        "51TUG",
        "51UUV",
        "51UVV",
        "51UTU",
        "51UUU",
        "51UVU",
        "51UTT",
        "51UUT",
        "51UVT",
        "51UXT",
        "51UTS",
        "51UUS",
        "51UVS",
        "51UWS",
        "51UXS",
        "51UYS",
        "51UTR",
        "51UUR",
        "51UVR",
        "51UWR",
        "51UXR",
        "51UTQ",
        "51UUQ",
        "51UVQ",
        "51UWQ",
        "51UXQ",
        "51UTP",
        "51UUP",
        "51UVP",
        "51UWP",
        "51UXP",
        "52UBB"
    ]
        }
        context_dict = {
            'ESA下载':{
                "tileds": tileds,
                "folder": r"Z:\Sentinel2Zip",
                'province': "请选择省份（非必须）" ,
                'tilesstr': '',
                'startdate': '',
                'threads':4,
                'clouds':100,
                'sleeptime':90,
                'enddate': '',
                "years": list(range(datetime.datetime.now().year,2016,-1)),
                'accounts':{
                    "fyy001": "show1234",
                    "fyy_01": "show1234",
                    "fyy_02": "show1234",
                    "fyy_03": "show1234",
                    "fyy_04": "show1234",
                    "wyq01": "show970213",
                    "wyq02": "show970213",
                    "wyq03": "show970213",
                    "wyq04": "show970213",
                    "wyq05": "show970213",
                    "wyq06": "show970213",
                    "wyq07": "show970213",
                    "hxx2021": "hxx2021123",
                    "hxx2022": "hxx2022123",
                    "hxx20221": "hxx2022123",
                    "hxx20222": "hxx20222123"
                },
            },
            'PEPS下载':{
                "tileds": tileds,
                "folder": r"Z:\Sentinel2Zip",
                'province': "请选择省份（非必须）" ,
                'tilesstr': '',
                'startdate': '',
                'enddate': '',
                'threads':10,
                'clouds':100,
                "years": list(range(datetime.datetime.now().year,2016,-1)),
                'accounts':{"fengzhipo@outlook.com": '3edc@WSX'},
            },
            '合成栅格':{
                "tileds": tileds,
                "source_folder": r"Z:\Sentinel2Zip",
                # 'threads':10,
                'clouds':100,
                "years": list(range(datetime.datetime.now().year,2016,-1)),
                'target_folder': r"Z:\ProvinceTif",
            },
            '查询数据':{
                "tileds": tileds,
                "folder": r"Z:\Sentinel2Zip",
                'clouds':100,
                'ip':{
                    'local host': {"username": "", "password": ""},
                    '192.168.2.172': {"username": "root", "password":"DELL123dell"},
                    '192.168.1.83': {"username": "root", "password":"gykj@123"},
                    '192.168.1.82': {"username": "root", "password":"000000"}
                },
                "years": list(range(datetime.datetime.now().year,2016,-1)),
            },
            '3A数据服务':{
                "tileds": tileds,
                'python_path':r"/home/fengyangyang/python_env_1/bin/python",
                'script_path':r'/home/fengyangyang/projection_1/Gy100RasterServer.py',
                'gykm_dir':r"/data/jiabing/Automatic_interpretation",
                'base_dir':r"/83To82/multispectral/Automatic_interpretation",
                'sshargs': {'ip':'192.168.1.82','port':"22","username":"root","password":"000000"},
                'bands':["2","3","4","5","6","7","8","8A","11","12","99"],
                "years": list(range(datetime.datetime.now().year,2016,-1)),
            }
        }
        with open(file_path,"w",encoding='utf-8') as json_file:
            json_str = json.dumps(context_dict,ensure_ascii=False,indent=4)
            json_file.write(json_str)  
    else: 
        with open(file_path,"r",encoding='utf-8') as json_file:
            context_dict = json.load(json_file)
    return context_dict


class UI:

    width, height = 742, 820
    title = '哨兵工具（国源内部使用）'

    def __init__(self):
        context_dict = load_configfile()
    
        self.get_window() 
        tkinter.ttk.Style().configure(
            'TNotebook',  
            background='Teal', # 'LightSteelBlue'
        )
        notebook = tkinter.ttk.Notebook(self.window,width=self.width)
      
        # notebook.pack(padx=[0,0],pady=[0,0],fill=tk.BOTH,expand=True)
        notebook.grid(column=0,row=0,padx=(0,0),pady=(0,0))

        sentinelraster = raster3Aserve_page(self.window,context_dict['3A数据服务'])
        notebook.add(
            sentinelraster.frame,
            text=' 3A数据服务 ',
            state='normal',
            padding=[0,0,0,0],
            # underline=None
        )

        checksentinel = checksentinel_page(self.window,context_dict['查询数据'])
        notebook.add(
            checksentinel.frame,
            text=' 查询数据 ',
            state='normal',
            padding=[0,0,0,0],
            # underline=None
        )

        esadonwload = esadonwload_page(self.window,context_dict['ESA下载'])
        notebook.add(
            esadonwload.frame,
            text=' 下载方式二 ',
            state='normal',
            padding=[0,0,0,0],
            # underline=None
        )

        pepsdownload = pepsdownload_page(self.window,context_dict['PEPS下载'])
        notebook.add(
            pepsdownload.frame,
            text=' 下载方式一 ',
            state='normal',
            padding=[0,0,0,0],
            # underline=None
        )

        sentinelraster = sentinelraster_page(self.window,context_dict['合成栅格'])
        notebook.add(
            sentinelraster.frame,
            text=' 合成栅格 ',
            state='normal',
            padding=[0,0,0,0],
            # underline=None
        )
        
        self.window.bind('<Escape>', lambda e:self.window.quit())
        self.window.mainloop()

    def get_window(self):
        """get_window : 主题窗口
        """
        self.window = tk.Tk()
        self.window.title(self.title)
        screenwidth = self.window.winfo_screenwidth() # 屏幕宽度
        screenheight = self.window.winfo_screenheight() # 屏幕高度
        x = int((screenwidth - self.width) / 2)
        y = int((screenheight - self.height) / 2)
        locat = f"{self.width}x{self.height}+{x}+{y}"
        self.window.geometry(locat) # 大小以及位置
        self.window.resizable(0,0) 

        self.window.iconphoto(False,tk.PhotoImage(file=r'./gykjLogo_1.png'))
        return


class esadonwload_page:

    def __init__(self,window,params):

        tkinter.ttk.Style().configure(
            'b.TLabelframe',  
            relief="ridge",
            borderwidth=4,
            background='LightBlue', # 'LightSteelBlue'
        )

        tkinter.ttk.Style().configure(
            'a.TLabel', 
            font=('黑体','10',''), 
            background='LightBlue', # 'LightSteelBlue' # Lavender
            foreground="Navy",
            bordercolor='black',
        )

        tkinter.ttk.Style().configure(
            'b.TLabel', 
            font=('黑体','10',''), 
            background='LightBlue',  # 'LightSteelBlue' PaleTurquoise LightBlue
            foreground="black",
            bordercolor='black',
        )

        tkinter.ttk.Style().configure(
            'a.TButton', 
            font=('黑体','10',''),
            relief="raised", 
            foreground="black",  # block
            background='RoyalBlue',
            width=10,
        )

        tkinter.ttk.Style().configure(
            'TFrame', 
            font=('黑体','16',''), 
            fg='red',
            background='Azure',
        )

        tkinter.ttk.Style().configure(
            'Horizontal.TScale', 
            background='LightSteelBlue',
        )
        
        self.frame = tkinter.ttk.Frame(window)

        self.params = params
        line_iter = iter(range(50)) 
        self.sentinel_frame(self.frame,next(line_iter)) # 输入列表 （省份选择）
        self.period_frame(self.frame,next(line_iter))  # 时期选择
        self.thread_frame(self.frame,next(line_iter))  # 线程数量选择
        self.cloud_frame(self.frame,next(line_iter))  # 最大含云量选择
        self.sleep_frame(self.frame,next(line_iter)) # 间隔时长
        self.account_frame(self.frame,next(line_iter))
        self.folder_frame(self.frame,next(line_iter))  #  获取下载目录
        self.task_frame(self.frame,next(line_iter))  #  开启下载任务

    def sentinel_frame(self,master,row):
        frame = tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='输入图幅列表',style='a.TLabel')) #  style='b.TLabelframe',
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')  
        self.tiles_str=tk.StringVar();self.tiles_str.set('请输入图幅（例如：51RTH-51RUH）')
        entry=tkinter.ttk.Entry(frame,width=64,textvariable=self.tiles_str) # font = ('', '14', 'bold')
        entry.grid(column=0,row=0,padx=[10,0],sticky='we') 
        scroll=tkinter.ttk.Scrollbar(frame,orient=tk.HORIZONTAL,cursor="arrow")
        scroll.grid(column=0,row=1,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,text="图幅",style='b.TLabel'
        ).grid(column=1,row=0,ipadx=10,sticky='we')
        self.province=tk.StringVar();self.province.set('请选择省份（可选）')
        values=list(self.params['tileds'].keys())
        combobox=tkinter.ttk.Combobox(frame,textvariable=self.province,values=values)  # state='readonly',
        combobox.grid(column=2,row=0,sticky='we')
        tkinter.ttk.Label(frame,text="省份",style='b.TLabel').grid(column=3,row=0)
        scroll.config(command=entry.xview)
        entry.config(xscrollcommand=scroll.set)
        combobox.bind(
            '<<ComboboxSelected>>', 
            lambda event:self.tiles_str.set("-".join(self.params['tileds'][self.province.get()])))
        return

    def period_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='选择起止日期',style='a.TLabel'))
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')
        today = datetime.date.today()
        tkinter.ttk.Label(frame,text="开始时间：",style='b.TLabel'
        ).grid(column=0,row=0,padx=(5,0),pady=[0,0],sticky='we')
        self.start_year = tk.IntVar();self.start_year.set(today.year)
        values=self.params['years']
        start_year_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_year,values=values) # state='readonly',
        start_year_cb.grid(column=1,row=0,padx=(10,0),pady=[0,0],sticky='we')
        self.start_month = tk.IntVar();self.start_month.set(today.month)
        values=tuple(range(1,13))
        start_month_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_month,values=values)
        start_month_cb.grid(column=2,row=0,padx=[40,0],pady=[0,0],sticky='we')
        self.start_day = tk.IntVar();self.start_day.set(1)
        values=lambda:list(range(3,rangeM(self.start_year.get(),self.start_month.get())[1]+1))
        start_day_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_day,values=values())
        start_day_cb.grid(column=3,row=0,padx=[40,0],pady=[0,0],sticky='we')
        tkinter.ttk.Label(frame,text="结束时间：",style='b.TLabel'
        ).grid(column=0,row=1,padx=(5,0),pady=[10,0],sticky='we')
        self.end_year = tk.IntVar();self.end_year.set(today.year)
        values=self.params['years']
        end_year_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_year,values=values)
        end_year_cb.grid(column=1,row=1,padx=(10,0),pady=[10,0],sticky='we')
        self.end_month = tk.IntVar();self.end_month.set(today.month)
        values=tuple(range(1,13))
        end_month_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_month,values=values)
        end_month_cb.grid(column=2,row=1,padx=[40,0],pady=[10,0],sticky='we')
        self.end_day = tk.IntVar();self.end_day.set(today.day)
        values=lambda:list(range(1,rangeM(self.end_year.get(),self.end_month.get())[1]+1))
        end_day_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_day,values=values())
        end_day_cb.grid(column=3,row=1,padx=[40,0],pady=[10,0],sticky='we')
        start_year_cb.bind(
            '<<ComboboxSelected>>', 
            lambda event:(
                start_day_cb.config({"values":list(range(1,rangeM(
                    self.start_year.get(),self.start_month.get())[1]+1))}),
                start_day_cb.current(0)
            )
        )
        start_month_cb.bind(
            '<<ComboboxSelected>>',
            lambda event:(
                start_day_cb.config({"values":list(range(1,rangeM(
                    self.start_year.get(),self.start_month.get())[1]+1))}),
                start_day_cb.current(0)
            )
        )
        end_year_cb.bind(
            '<<ComboboxSelected>>', 
            lambda event:(
                end_day_cb.config({"values":list(range(1,rangeM(
                    self.end_year.get(),self.end_month.get())[1]+1))}),
                end_day_cb.current(rangeM(
                    self.end_year.get(),self.end_month.get())[1]-1)
            )
        )
        end_month_cb.bind(
            '<<ComboboxSelected>>',
            lambda event:(
                end_day_cb.config({"values":list(range(1,rangeM(
                    self.end_year.get(),self.end_month.get())[1]+1))}),
                end_day_cb.current(rangeM(
                    self.end_year.get(),self.end_month.get())[1]-1)
            )
        )
        return

    def thread_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置线程数量',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0),pady=(5,0),sticky='we') 
        self.thread_count = tk.IntVar();self.thread_count.set(self.params['threads'])
        label_text=tk.StringVar();label_text.set(f'{self.thread_count.get()}个线程')
        tkinter.ttk.Scale(
            frame,variable=self.thread_count,from_=1,to=4,orient=tk.HORIZONTAL,length=600,
            command=lambda event:label_text.set(f'{self.thread_count.get()}个线程')
        ).grid(column=0,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,textvariable=label_text,style='b.TLabel'
        ).grid(column=1,row=0,sticky='we')
        return

    def cloud_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置最大云量',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.max_clound = tk.IntVar();self.max_clound.set(self.params['clouds'])
        label_text=tk.StringVar();label_text.set(f'{self.max_clound.get()}%最大云量')
        tkinter.ttk.Scale(
            frame,variable=self.max_clound,from_=0,to=100,orient=tk.HORIZONTAL,length=600,
            command=lambda event:label_text.set(f'{self.max_clound.get()}%最大云量')
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,textvariable=label_text,style='b.TLabel'
        ).grid(column=2,row=0,sticky='we')
        return

    def sleep_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置间隔时长',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.sleep_time = tk.IntVar();self.sleep_time.set(self.params['sleeptime'])
        label_text=tk.StringVar();label_text.set(f'{self.sleep_time.get()}秒间隔时长')
        tkinter.ttk.Scale(
            frame,variable=self.sleep_time,from_=0,to=120,orient=tk.HORIZONTAL,length=600,
            command=lambda event:label_text.set(f'{self.sleep_time.get()}秒间隔时长')
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,textvariable=label_text,style='b.TLabel'
        ).grid(column=2,row=0,sticky='we')
        return

    def account_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='选择ESA用户',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.username = tk.StringVar();self.username.set('选择账户')
        self.password = tk.StringVar();self.password.set('账户密码')
        values = list(self.params['accounts'].keys())
        username_cb=tkinter.ttk.Combobox(frame,textvariable=self.username,values=values)
        username_cb.grid(column=0,row=0,padx=[10,0],sticky='we')
        password_cb = tkinter.ttk.Entry(frame,text="选择账户",textvariable=self.password)
        password_cb.grid(column=2,row=0,padx=[380,0],sticky='we')
        username_cb.bind(
            '<<ComboboxSelected>>',
            lambda event:(
                self.password.set(self.params['accounts'][self.username.get()]),
                password_cb.config({'show':'*'})
            )
        )
        return

    def folder_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置下载目录',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.save_folder = tk.StringVar();self.save_folder.set(r"Z:\Sentinel2Zip")
        tkinter.ttk.Entry(frame,width=85,textvariable=self.save_folder
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Button(
            frame,text="选择目录",style='a.TButton',
            command=lambda:self.save_folder.set(tkfa().replace('/','\\'))
        ).grid(column=2,row=0,padx=[10,0],sticky='we')
        return

    def task_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='监视任务进度',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.start_button=tkinter.ttk.Button(
            frame,text="开始任务",style='a.TButton',
            command=lambda:Thread(target=self.running,args=(),daemon=True).start())
        self.start_button.grid(column=0,row=0,padx=[10,0],sticky='we')
        self.progressbar = tkinter.ttk.Progressbar(
            frame,length=600,value=0,mode="indeterminate",orient=tk.HORIZONTAL)  # mode="determinate",
        self.progressbar.grid(column=1,row=0,padx=[10,0],sticky='we') 
        self.scrolled_text = scrolledtext.ScrolledText(
            frame,height=22,state='normal',wrap = tk.WORD,font="TkFixedFont") 
        self.scrolled_text.tag_config('INFO', foreground='black')
        self.scrolled_text.tag_config('DEBUG', foreground='gray')
        self.scrolled_text.tag_config('WARNING', foreground='orange')
        self.scrolled_text.tag_config('ERROR', foreground='red')
        self.scrolled_text.tag_config('CRITICAL', foreground='red', underline=1)
        self.scrolled_text.grid(column=0,row=1,columnspan=2,padx=[10,0],pady=[10,0],sticky='we')
        return

    def running(self):
        self.progressbar.start()
        self.start_button.configure(state=tk.DISABLED)
        self.scrolled_text.configure(state=tk.NORMAL)
        self.scrolled_text.delete(0.0, tkinter.END)

        def waring_end(info):
            self.start_button.config({"state":tk.NORMAL})
            self.scrolled_text.configure(state=tk.DISABLED)
            self.progressbar.stop()
            tk.messagebox.showwarning('Waring', info)
            return
        def print_line(temp):
            temp = f"{datetime.datetime.now().strftime('%H:%M:%S')}>{temp}\n"
            self.scrolled_text.insert(tk.END,temp)
            self.scrolled_text.see(tk.END)
            self.scrolled_text.focus()
            return
        try:
            self.start_date = datetime.date(
                self.start_year.get(),self.start_month.get(),self.start_day.get())
            self.end_date = datetime.date(
                self.end_year.get(),self.end_month.get(),self.end_day.get())
        except: return waring_end('日期选择错误！')
        if self.tiles_str.get() == '请输入图幅（例如：51RTH-51RUH）':return waring_end('未选择图幅！')
        elif self.start_date > self.end_date:return waring_end('日期选择错误！')
        elif self.username.get()=="选择账户":return waring_end('未选择ESA账户！')
        elif not os.path.exists(self.save_folder.get()):return waring_end('未选择目录！')
        else:
            print_line(f"下载图幅：{self.tiles_str.get().split('-')}")
            print_line(f"下载时期：{self.start_date}--->{self.end_date}")
            print_line(f"线程数量：{self.thread_count.get()}个")
            print_line(f"最大含云量：{self.max_clound.get()}%")
            print_line(f"间隔时长：{self.sleep_time.get()}S")
            print_line(f"保存目录：{self.save_folder.get()}")
            print_line(f"账户信息：(用户名){self.username.get()} (密码){self.password.get()[:-1]}*")  
        args=[
            self.username.get(),
            self.password.get(),
            self.tiles_str.get().split('-'),
            self.start_date.strftime("%Y-%m-%d"),
            self.end_date.strftime("%Y-%m-%d"),
            self.max_clound.get(),
            self.save_folder.get(),
            self.thread_count.get(),
            self.sleep_time.get()
        ]
        sdt.esa_downloader(*args)
        self.start_button.config({"state":tk.NORMAL})
        self.scrolled_text.configure(state=tk.DISABLED)
        self.progressbar.stop()
        tk.messagebox.showinfo('温馨提示','下载完成！')
        return


class pepsdownload_page:

    def __init__(self,window,params):

        tkinter.ttk.Style().configure(
            'b.TLabelframe',  
            relief="ridge",
            borderwidth=4,
            background='LightBlue', # 'LightSteelBlue'
        )

        tkinter.ttk.Style().configure(
            'a.TLabel', 
            font=('黑体','10',''), 
            background='LightBlue', # 'LightSteelBlue' # Lavender
            foreground="Navy",
            bordercolor='black',
        )

        tkinter.ttk.Style().configure(
            'b.TLabel', 
            font=('黑体','10',''), 
            background='LightBlue',  # 'LightSteelBlue' PaleTurquoise LightBlue
            foreground="black",
            bordercolor='black',
        )

        tkinter.ttk.Style().configure(
            'a.TButton', 
            font=('黑体','10',''),
            relief="raised", 
            foreground="black",  # block
            background='RoyalBlue',
            width=10,
        )

        tkinter.ttk.Style().configure(
            'TFrame', 
            font=('黑体','16',''), 
            fg='red',
            background='Azure',
        )

        tkinter.ttk.Style().configure(
            'Horizontal.TScale', 
            background='LightSteelBlue',
        )

        self.frame = tkinter.ttk.Frame(window)
        self.params = params
        line_iter = iter(range(50)) 
        self.sentinel_frame(self.frame,next(line_iter)) # 输入列表 （省份选择）
        self.period_frame(self.frame,next(line_iter))  # 时期选择
        self.thread_frame(self.frame,next(line_iter))  # 线程数量选择
        self.cloud_frame(self.frame,next(line_iter))  # 最大含云量选择
        self.account_frame(self.frame,next(line_iter))
        self.folder_frame(self.frame,next(line_iter))  #  获取下载目录
        self.task_frame(self.frame,next(line_iter))  #  开启下载任务

    def sentinel_frame(self,master,row):
        frame = tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='输入图幅列表',style='a.TLabel')) #  style='b.TLabelframe',
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')  
        self.tiles_str=tk.StringVar();self.tiles_str.set('请输入图幅（例如：51RTH-51RUH）')
        entry=tkinter.ttk.Entry(frame,width=64,textvariable=self.tiles_str) # font = ('', '14', 'bold')
        entry.grid(column=0,row=0,padx=[10,0],sticky='we') 
        scroll=tkinter.ttk.Scrollbar(frame,orient=tk.HORIZONTAL,cursor="arrow")
        scroll.grid(column=0,row=1,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,text="图幅",style='b.TLabel'
        ).grid(column=1,row=0,ipadx=10,sticky='we')
        self.province=tk.StringVar();self.province.set('请选择省份（可选）')
        values=list(self.params['tileds'].keys())
        combobox=tkinter.ttk.Combobox(frame,textvariable=self.province,values=values)  # state='readonly',
        combobox.grid(column=2,row=0,sticky='we')
        tkinter.ttk.Label(frame,text="省份",style='b.TLabel').grid(column=3,row=0)
        scroll.config(command=entry.xview)
        entry.config(xscrollcommand=scroll.set)
        combobox.bind(
            '<<ComboboxSelected>>', 
            lambda event:self.tiles_str.set("-".join(self.params['tileds'][self.province.get()])))
        return

    def period_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='选择起止日期',style='a.TLabel'))
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')
        today = datetime.date.today()
        tkinter.ttk.Label(frame,text="开始时间：",style='b.TLabel'
        ).grid(column=0,row=0,padx=(5,0),pady=[0,0],sticky='we')
        self.start_year = tk.IntVar();self.start_year.set(today.year)
        values=self.params['years']
        start_year_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_year,values=values) # state='readonly',
        start_year_cb.grid(column=1,row=0,padx=(10,0),pady=[0,0],sticky='we')
        self.start_month = tk.IntVar();self.start_month.set(today.month)
        values=tuple(range(1,13))
        start_month_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_month,values=values)
        start_month_cb.grid(column=2,row=0,padx=[40,0],pady=[0,0],sticky='we')
        self.start_day = tk.IntVar();self.start_day.set(1)
        values=lambda:list(range(3,rangeM(self.start_year.get(),self.start_month.get())[1]+1))
        start_day_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_day,values=values())
        start_day_cb.grid(column=3,row=0,padx=[40,0],pady=[0,0],sticky='we')
        tkinter.ttk.Label(frame,text="结束时间：",style='b.TLabel'
        ).grid(column=0,row=1,padx=(5,0),pady=[10,0],sticky='we')
        self.end_year = tk.IntVar();self.end_year.set(today.year)
        values=self.params['years']
        end_year_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_year,values=values)
        end_year_cb.grid(column=1,row=1,padx=(10,0),pady=[10,0],sticky='we')
        self.end_month = tk.IntVar();self.end_month.set(today.month)
        values=tuple(range(1,13))
        end_month_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_month,values=values)
        end_month_cb.grid(column=2,row=1,padx=[40,0],pady=[10,0],sticky='we')
        self.end_day = tk.IntVar();self.end_day.set(today.day)
        values=lambda:list(range(1,rangeM(self.end_year.get(),self.end_month.get())[1]+1))
        end_day_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_day,values=values())
        end_day_cb.grid(column=3,row=1,padx=[40,0],pady=[10,0],sticky='we')
        start_year_cb.bind(
            '<<ComboboxSelected>>', 
            lambda event:(
                start_day_cb.config({"values":list(range(1,rangeM(
                    self.start_year.get(),self.start_month.get())[1]+1))}),
                start_day_cb.current(0)
            )
        )
        start_month_cb.bind(
            '<<ComboboxSelected>>',
            lambda event:(
                start_day_cb.config({"values":list(range(1,rangeM(
                    self.start_year.get(),self.start_month.get())[1]+1))}),
                start_day_cb.current(0)
            )
        )
        end_year_cb.bind(
            '<<ComboboxSelected>>', 
            lambda event:(
                end_day_cb.config({"values":list(range(1,rangeM(
                    self.end_year.get(),self.end_month.get())[1]+1))}),
                end_day_cb.current(rangeM(
                    self.end_year.get(),self.end_month.get())[1]-1)
            )
        )
        end_month_cb.bind(
            '<<ComboboxSelected>>',
            lambda event:(
                end_day_cb.config({"values":list(range(1,rangeM(
                    self.end_year.get(),self.end_month.get())[1]+1))}),
                end_day_cb.current(rangeM(
                    self.end_year.get(),self.end_month.get())[1]-1)
            )
        )
        return

    def thread_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置线程数量',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0),pady=(5,0),sticky='we') 
        self.thread_count = tk.IntVar();self.thread_count.set(self.params['threads'])
        label_text=tk.StringVar();label_text.set(f'{self.thread_count.get()}个线程')
        tkinter.ttk.Scale(
            frame,variable=self.thread_count,from_=1,to=10,orient=tk.HORIZONTAL,length=600,
            command=lambda event:label_text.set(f'{self.thread_count.get()}个线程')
        ).grid(column=0,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,textvariable=label_text,style='b.TLabel'
        ).grid(column=1,row=0,sticky='we')
        return

    def cloud_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置最大云量',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.max_clound = tk.IntVar();self.max_clound.set(self.params['clouds'])
        label_text=tk.StringVar();label_text.set(f'{self.max_clound.get()}%最大云量')
        tkinter.ttk.Scale(
            frame,variable=self.max_clound,from_=0,to=100,orient=tk.HORIZONTAL,length=600,
            command=lambda event:label_text.set(f'{self.max_clound.get()}%最大云量')
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,textvariable=label_text,style='b.TLabel'
        ).grid(column=2,row=0,sticky='we')
        return

    def account_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='选择注册用户',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.username = tk.StringVar();self.username.set('选择账户')
        self.password = tk.StringVar();self.password.set('账户密码')
        values = list(self.params['accounts'].keys())
        username_cb=tkinter.ttk.Combobox(frame,textvariable=self.username,values=values)
        username_cb.grid(column=0,row=0,padx=[10,0],sticky='we')
        password_cb = tkinter.ttk.Entry(frame,text="选择账户",textvariable=self.password)
        password_cb.grid(column=2,row=0,padx=[380,0],sticky='we')
        username_cb.bind(
            '<<ComboboxSelected>>',
            lambda event:(
                self.password.set(self.params['accounts'][self.username.get()]),
                password_cb.config({'show':'*'})
            )
        )
        return

    def folder_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置下载目录',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.save_folder = tk.StringVar();self.save_folder.set(r"Z:\Sentinel2Zip")
        tkinter.ttk.Entry(frame,width=85,textvariable=self.save_folder
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Button(
            frame,text="选择目录",style='a.TButton',
            command=lambda:self.save_folder.set(tkfa().replace('/','\\'))
        ).grid(column=2,row=0,padx=[10,0],sticky='we')
        return

    def task_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='监视任务进度',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.start_button=tkinter.ttk.Button(
            frame,text="开始任务",style='a.TButton',
            command=lambda:Thread(target=self.running,args=(),daemon=True).start())
        self.start_button.grid(column=0,row=0,padx=[10,0],sticky='we')
        self.progressbar = tkinter.ttk.Progressbar(
            frame,length=600,value=0,mode="indeterminate",orient=tk.HORIZONTAL)  # mode="determinate",
        self.progressbar.grid(column=1,row=0,padx=[10,0],sticky='we') 
        self.scrolled_text = scrolledtext.ScrolledText(
            frame,height=26,state='normal',wrap = tk.WORD,font="TkFixedFont") 
        self.scrolled_text.tag_config('INFO', foreground='black')
        self.scrolled_text.tag_config('DEBUG', foreground='gray')
        self.scrolled_text.tag_config('WARNING', foreground='orange')
        self.scrolled_text.tag_config('ERROR', foreground='red')
        self.scrolled_text.tag_config('CRITICAL', foreground='red', underline=1)
        self.scrolled_text.grid(column=0,row=1,columnspan=2,padx=[10,0],pady=[10,0],sticky='we')
        return

    def running(self):
        self.progressbar.start()
        self.start_button.configure(state=tk.DISABLED)
        self.scrolled_text.configure(state=tk.NORMAL)
        self.scrolled_text.delete(0.0, tkinter.END)

        def waring_end(info):
            self.start_button.config({"state":tk.NORMAL})
            self.scrolled_text.configure(state=tk.DISABLED)
            self.progressbar.stop()
            tk.messagebox.showwarning('Waring', info)
            return
        def print_line(temp):
            temp = f"{datetime.datetime.now().strftime('%H:%M:%S')}>{temp}\n"
            self.scrolled_text.insert(tk.END,temp)
            self.scrolled_text.see(tk.END)
            self.scrolled_text.focus()
            return
        try:
            self.start_date = datetime.date(
                self.start_year.get(),self.start_month.get(),self.start_day.get())
            self.end_date = datetime.date(
                self.end_year.get(),self.end_month.get(),self.end_day.get())
        except: return waring_end('日期选择错误！')
        if self.tiles_str.get() == '请输入图幅（例如：51RTH-51RUH）':return waring_end('未选择图幅！')
        elif self.start_date > self.end_date:return waring_end('日期选择错误！')
        elif self.username.get()=="选择账户":return waring_end('未选择ESA账户！')
        elif not os.path.exists(self.save_folder.get()):return waring_end('未选择目录！')
        else:
            print_line(f"下载图幅：{self.tiles_str.get().split('-')}")
            print_line(f"下载时期：{self.start_date}--->{self.end_date}")
            print_line(f"线程数量：{self.thread_count.get()}个")
            print_line(f"最大含云量：{self.max_clound.get()}%")
            print_line(f"保存目录：{self.save_folder.get()}")
            print_line(f"账户信息：(用户名){self.username.get()} (密码){self.password.get()[:-1]}*")  
        args=[
            self.username.get(),
            self.password.get(),
            self.tiles_str.get().split('-'),
            self.start_date.strftime("%Y-%m-%d"),
            self.end_date.strftime("%Y-%m-%d"),
            self.max_clound.get(),
            self.save_folder.get(),
            self.thread_count.get(),

        ]
        sdt.peps_downloader(*args)
        self.start_button.config({"state":tk.NORMAL})
        self.scrolled_text.configure(state=tk.DISABLED)
        self.progressbar.stop()
        tk.messagebox.showinfo('温馨提示','下载完成！')
        return


class sentinelraster_page:

    def __init__(self,window,params):

        tkinter.ttk.Style().configure(
            'b.TLabelframe',  
            relief="ridge",
            borderwidth=4,
            background='LightBlue', # 'LightSteelBlue'
        )

        tkinter.ttk.Style().configure(
            'a.TLabel', 
            font=('黑体','10',''), 
            background='LightBlue', # 'LightSteelBlue' # Lavender
            foreground="Navy",
            bordercolor='black',
        )

        tkinter.ttk.Style().configure(
            'b.TLabel', 
            font=('黑体','10',''), 
            background='LightBlue',  # 'LightSteelBlue' PaleTurquoise LightBlue
            foreground="black",
            bordercolor='black',
        )

        tkinter.ttk.Style().configure(
            'a.TButton', 
            font=('黑体','10',''),
            relief="raised", 
            foreground="black",  # block
            background='RoyalBlue',
            width=10,
        )

        tkinter.ttk.Style().configure(
            'TFrame', 
            font=('黑体','16',''), 
            fg='red',
            background='Azure',
        )

        tkinter.ttk.Style().configure(
            'Horizontal.TScale', 
            background='LightSteelBlue',
        )

        self.frame = tkinter.ttk.Frame(window)
        self.params = params
        line_iter = iter(range(50)) 
        self.sentinel_frame(self.frame,next(line_iter)) # 输入列表 （省份选择）
        self.period_frame(self.frame,next(line_iter))  # 时期选择
        self.cloud_frame(self.frame,next(line_iter))  # 最大含云量选择
        self.sourcedir_frame(self.frame,next(line_iter))  #  获取zip目录
        self.targetdir_frame(self.frame,next(line_iter))  #  获取tif目录
        self.task_frame(self.frame,next(line_iter))  #  开启下载任务

    def sentinel_frame(self,master,row):
        frame = tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='输入图幅列表',style='a.TLabel')) #  style='b.TLabelframe',
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')  
        self.tiles_str=tk.StringVar();self.tiles_str.set('请输入图幅（例如：51RTH-51RUH）')
        entry=tkinter.ttk.Entry(frame,width=64,textvariable=self.tiles_str) # font = ('', '14', 'bold')
        entry.grid(column=0,row=0,padx=[10,0],sticky='we') 
        scroll=tkinter.ttk.Scrollbar(frame,orient=tk.HORIZONTAL,cursor="arrow")
        scroll.grid(column=0,row=1,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,text="图幅",style='b.TLabel'
        ).grid(column=1,row=0,ipadx=10,sticky='we')
        self.province=tk.StringVar();self.province.set('请选择省份（可选）')
        values=list(self.params['tileds'].keys())
        combobox=tkinter.ttk.Combobox(frame,textvariable=self.province,values=values)  # state='readonly',
        combobox.grid(column=2,row=0,sticky='we')
        tkinter.ttk.Label(frame,text="省份",style='b.TLabel').grid(column=3,row=0)
        scroll.config(command=entry.xview)
        entry.config(xscrollcommand=scroll.set)
        combobox.bind(
            '<<ComboboxSelected>>', 
            lambda event:self.tiles_str.set("-".join(self.params['tileds'][self.province.get()])))
        return
    
    def region_frame(self,master,row):
        frame = tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='选择行政区划',style='a.TLabel')) #  style='b.TLabelframe',
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')
        
        self.province=tk.StringVar();self.province.set('请选择省份')
        values=list(self.params['tileds'].keys())
        province_combobox=tkinter.ttk.Combobox(
            frame,textvariable=self.province,state='readonly',values=values)  # state='readonly',
        province_combobox.grid(column=0,row=0,padx=(10,0),pady=(0,0),sticky='we')
        tkinter.ttk.Label(frame,text="省份",style='b.TLabel').grid(column=1,row=0)

        self.city=tk.StringVar();self.city.set('请选择地市')
        values=list(self.params['tileds'].keys())
        city_combobox=tkinter.ttk.Combobox(
            frame,textvariable=self.city,state='readonly',values=values)  # state='readonly',
        city_combobox.grid(column=2,row=0,padx=(40,0),pady=(0,0),sticky='we')
        tkinter.ttk.Label(frame,text="地市",style='b.TLabel').grid(column=3,row=0)

        self.county=tk.StringVar();self.county.set('请选择县区')
        values=list(self.params['tileds'].keys())
        county_combobox=tkinter.ttk.Combobox(
            frame,textvariable=self.county,state='readonly',values=values)  # state='readonly',
        county_combobox.grid(column=4,row=0,padx=(40,0),pady=(0,0),sticky='we')
        tkinter.ttk.Label(frame,text="县区",style='b.TLabel').grid(column=5,row=0)

        # combobox.bind(
        #     '<<ComboboxSelected>>', 
        #     lambda event:self.tiles_str.set("-".join(self.params['tileds'][self.province.get()])))
        return

    def period_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='选择起止日期',style='a.TLabel'))
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')
        today = datetime.date.today()
        tkinter.ttk.Label(frame,text="开始时间：",style='b.TLabel'
        ).grid(column=0,row=0,padx=(5,0),pady=[0,0],sticky='we')
        self.start_year = tk.IntVar();self.start_year.set(today.year)
        values=self.params['years']
        start_year_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_year,values=values) # state='readonly',
        start_year_cb.grid(column=1,row=0,padx=(10,0),pady=[0,0],sticky='we')
        self.start_month = tk.IntVar();self.start_month.set(today.month)
        values=tuple(range(1,13))
        start_month_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_month,values=values)
        start_month_cb.grid(column=2,row=0,padx=[40,0],pady=[0,0],sticky='we')
        self.start_day = tk.IntVar();self.start_day.set(1)
        values=lambda:list(range(3,rangeM(self.start_year.get(),self.start_month.get())[1]+1))
        start_day_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_day,values=values())
        start_day_cb.grid(column=3,row=0,padx=[40,0],pady=[0,0],sticky='we')
        tkinter.ttk.Label(frame,text="结束时间：",style='b.TLabel'
        ).grid(column=0,row=1,padx=(5,0),pady=[10,0],sticky='we')
        self.end_year = tk.IntVar();self.end_year.set(today.year)
        values=self.params['years']
        end_year_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_year,values=values)
        end_year_cb.grid(column=1,row=1,padx=(10,0),pady=[10,0],sticky='we')
        self.end_month = tk.IntVar();self.end_month.set(today.month)
        values=tuple(range(1,13))
        end_month_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_month,values=values)
        end_month_cb.grid(column=2,row=1,padx=[40,0],pady=[10,0],sticky='we')
        self.end_day = tk.IntVar();self.end_day.set(today.day)
        values=lambda:list(range(1,rangeM(self.end_year.get(),self.end_month.get())[1]+1))
        end_day_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_day,values=values())
        end_day_cb.grid(column=3,row=1,padx=[40,0],pady=[10,0],sticky='we')
        start_year_cb.bind(
            '<<ComboboxSelected>>', 
            lambda event:(
                start_day_cb.config({"values":list(range(1,rangeM(
                    self.start_year.get(),self.start_month.get())[1]+1))}),
                start_day_cb.current(0)
            )
        )
        start_month_cb.bind(
            '<<ComboboxSelected>>',
            lambda event:(
                start_day_cb.config({"values":list(range(1,rangeM(
                    self.start_year.get(),self.start_month.get())[1]+1))}),
                start_day_cb.current(0)
            )
        )
        end_year_cb.bind(
            '<<ComboboxSelected>>', 
            lambda event:(
                end_day_cb.config({"values":list(range(1,rangeM(
                    self.end_year.get(),self.end_month.get())[1]+1))}),
                end_day_cb.current(rangeM(
                    self.end_year.get(),self.end_month.get())[1]-1)
            )
        )
        end_month_cb.bind(
            '<<ComboboxSelected>>',
            lambda event:(
                end_day_cb.config({"values":list(range(1,rangeM(
                    self.end_year.get(),self.end_month.get())[1]+1))}),
                end_day_cb.current(rangeM(
                    self.end_year.get(),self.end_month.get())[1]-1)
            )
        )
        return

    def cloud_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置最大云量',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.max_clound = tk.IntVar();self.max_clound.set(self.params['clouds'])
        label_text=tk.StringVar();label_text.set(f'{self.max_clound.get()}%最大云量')
        tkinter.ttk.Scale(
            frame,variable=self.max_clound,from_=0,to=100,orient=tk.HORIZONTAL,length=600,
            command=lambda event:label_text.set(f'{self.max_clound.get()}%最大云量')
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,textvariable=label_text,style='b.TLabel'
        ).grid(column=2,row=0,sticky='we')
        return

    def sourcedir_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置zip目录',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.source_dir = tk.StringVar();self.source_dir.set(self.params['source_folder'])
        tkinter.ttk.Entry(frame,width=85,textvariable=self.source_dir
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Button(
            frame,text="选择目录",style='a.TButton',
            command=lambda:self.source_dir.set(tkfa().replace('/','\\'))
        ).grid(column=2,row=0,padx=[10,0],sticky='we')
        return

    def targetdir_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置tif目录',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')

        self.target_dir = tk.StringVar();self.target_dir.set(self.params['target_folder'])
        tkinter.ttk.Entry(frame,width=85,textvariable=self.target_dir
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Button(
            frame,text="选择目录",style='a.TButton',
            command=lambda:self.target_dir.set(tkfa().replace('/','\\'))
        ).grid(column=2,row=0,padx=[10,0],sticky='we')
        return

    def task_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='监视任务进度',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.start_button=tkinter.ttk.Button(
            frame,text="开始任务",style='a.TButton',
            command=lambda:Thread(target=self.running,args=(),daemon=True).start())
        self.start_button.grid(column=0,row=0,padx=[10,0],sticky='we')
        self.progressbar = tkinter.ttk.Progressbar(
            frame,length=600,value=0,mode="indeterminate",orient=tk.HORIZONTAL)  # mode="determinate",
        self.progressbar.grid(column=1,row=0,padx=[10,0],sticky='we') 
        self.scrolled_text = scrolledtext.ScrolledText(
            frame,height=31,state='normal',wrap = tk.WORD,font="TkFixedFont") 
        self.scrolled_text.tag_config('INFO', foreground='black')
        self.scrolled_text.tag_config('DEBUG', foreground='gray')
        self.scrolled_text.tag_config('WARNING', foreground='orange')
        self.scrolled_text.tag_config('ERROR', foreground='red')
        self.scrolled_text.tag_config('CRITICAL', foreground='red', underline=1)
        self.scrolled_text.grid(column=0,row=1,columnspan=2,padx=[10,0],pady=[10,0],sticky='we')
        return

    def running(self):
        self.progressbar.start()
        self.start_button.configure(state=tk.DISABLED)
        self.scrolled_text.configure(state=tk.NORMAL)
        self.scrolled_text.delete(0.0, tkinter.END)

        def waring_end(info):
            self.start_button.config({"state":tk.NORMAL})
            self.scrolled_text.configure(state=tk.DISABLED)
            self.progressbar.stop()
            tk.messagebox.showwarning('Waring', info)
            return
        def print_line(temp):
            temp = f"{datetime.datetime.now().strftime('%H:%M:%S')}>{temp}\n"
            self.scrolled_text.insert(tk.END,temp)
            self.scrolled_text.see(tk.END)
            self.scrolled_text.focus()
            return
        try:
            self.start_date = datetime.date(
                self.start_year.get(),self.start_month.get(),self.start_day.get())
            self.end_date = datetime.date(
                self.end_year.get(),self.end_month.get(),self.end_day.get())
        except: return waring_end('日期选择错误！')
        if self.tiles_str.get() == '请输入图幅（例如：51RTH-51RUH）':self.tiles_str.set('')
        elif self.tiles_str.get() == "" :self.tiles_str.set('')
        elif self.province.get() == "请选择省份（可选）" :self.province.set('')
        elif self.start_date > self.end_date:return waring_end('日期选择错误！')
        elif not os.path.exists(self.source_dir.get()):return waring_end('未选择zip目录！')
        elif not os.path.exists(self.target_dir.get()):return waring_end('未选择tif目录！')
        else:
            print_line(f"图幅：{self.tiles_str.get().split('-')}")
            print_line(f"时期：{self.start_date}--->{self.end_date}")
            print_line(f"省份：{self.province.get()}")
            print_line(f"最大含云量：{self.max_clound.get()}%")
            print_line(f"zip目录：{self.source_dir.get()}")
            print_line(f"tif目录：{self.target_dir.get()}")
        tiles= [] if self.tiles_str.get().split('-')==[''] else self.tiles_str.get().split('-')
        args=[
            self.source_dir.get(),
            self.target_dir.get(),
            self.start_date.strftime("%Y-%m-%d"),
            self.end_date.strftime("%Y-%m-%d"),
            tiles,
            self.province.get(),
            self.max_clound.get(),
        ]
        gsr.main(*args)
        self.start_button.config({"state":tk.NORMAL})
        self.scrolled_text.configure(state=tk.DISABLED)
        self.progressbar.stop()
        tk.messagebox.showinfo('温馨提示','任务完成！')
        return


class checksentinel_page:

    def __init__(self,window,params):
        self.window=window

        tkinter.ttk.Style().configure(
            'b.TLabelframe',  
            relief="ridge",
            borderwidth=4,
            background='LightBlue', # 'LightSteelBlue'
        )

        tkinter.ttk.Style().configure(
            'a.TLabel', 
            font=('黑体','10',''), 
            background='LightBlue', # 'LightSteelBlue' # Lavender
            foreground="Navy",
            bordercolor='black',
        )

        tkinter.ttk.Style().configure(
            'b.TLabel', 
            font=('黑体','10',''), 
            background='LightBlue',  # 'LightSteelBlue' PaleTurquoise LightBlue
            foreground="black",
            bordercolor='black',
        )

        tkinter.ttk.Style().configure(
            'a.TButton', 
            font=('黑体','10',''),
            relief="raised", 
            foreground="black",  # block
            background='RoyalBlue',
            width=10,
        )

        tkinter.ttk.Style().configure(
            'TFrame', 
            font=('黑体','16',''), 
            fg='red',
            background='Azure',
        )

        tkinter.ttk.Style().configure(
            'Horizontal.TScale', 
            background='LightSteelBlue',
        )

        self.frame = tkinter.ttk.Frame(self.window)
        self.params = params
        line_iter = iter(range(50)) 
        self.sentinel_frame(self.frame,next(line_iter)) # 输入列表 （省份选择）
        self.period_frame(self.frame,next(line_iter))  # 时期选择
        self.cloud_frame(self.frame,next(line_iter))  # 最大含云量选择
        self.server_frame(self.frame,next(line_iter))  #  设置ssh连接
        self.task_frame(self.frame,next(line_iter))  #  开启任务

    def sentinel_frame(self,master,row):
        frame = tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='输入图幅列表',style='a.TLabel')) #  style='b.TLabelframe',
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')  
        self.tiles_str=tk.StringVar();self.tiles_str.set('请输入图幅（例如：51RTH-51RUH）')
        entry=tkinter.ttk.Entry(frame,width=64,textvariable=self.tiles_str) # font = ('', '14', 'bold')
        entry.grid(column=0,row=0,padx=[10,0],sticky='we') 
        scroll=tkinter.ttk.Scrollbar(frame,orient=tk.HORIZONTAL,cursor="arrow")
        scroll.grid(column=0,row=1,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,text="图幅",style='b.TLabel'
        ).grid(column=1,row=0,ipadx=10,sticky='we')
        self.province=tk.StringVar();self.province.set('请选择省份（可选）')
        values=list(self.params['tileds'].keys())
        combobox=tkinter.ttk.Combobox(frame,textvariable=self.province,values=values)  # state='readonly',
        combobox.grid(column=2,row=0,sticky='we')
        tkinter.ttk.Label(frame,text="省份",style='b.TLabel').grid(column=3,row=0)
        scroll.config(command=entry.xview)
        entry.config(xscrollcommand=scroll.set)
        combobox.bind(
            '<<ComboboxSelected>>', 
            lambda event:self.tiles_str.set("-".join(self.params['tileds'][self.province.get()])))
        return

    def period_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='选择起止日期',style='a.TLabel'))
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')
        today = datetime.date.today()
        tkinter.ttk.Label(frame,text="开始时间：",style='b.TLabel'
        ).grid(column=0,row=0,padx=(5,0),pady=[0,0],sticky='we')
        self.start_year = tk.IntVar();self.start_year.set(today.year)
        values=self.params['years']
        start_year_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_year,values=values) # state='readonly',
        start_year_cb.grid(column=1,row=0,padx=(10,0),pady=[0,0],sticky='we')
        self.start_month = tk.IntVar();self.start_month.set(today.month)
        values=tuple(range(1,13))
        start_month_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_month,values=values)
        start_month_cb.grid(column=2,row=0,padx=[40,0],pady=[0,0],sticky='we')
        self.start_day = tk.IntVar();self.start_day.set(1)
        values=lambda:list(range(3,rangeM(self.start_year.get(),self.start_month.get())[1]+1))
        start_day_cb=tkinter.ttk.Combobox(frame,textvariable=self.start_day,values=values())
        start_day_cb.grid(column=3,row=0,padx=[40,0],pady=[0,0],sticky='we')
        tkinter.ttk.Label(frame,text="结束时间：",style='b.TLabel'
        ).grid(column=0,row=1,padx=(5,0),pady=[10,0],sticky='we')
        self.end_year = tk.IntVar();self.end_year.set(today.year)
        values=self.params['years']
        end_year_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_year,values=values)
        end_year_cb.grid(column=1,row=1,padx=(10,0),pady=[10,0],sticky='we')
        self.end_month = tk.IntVar();self.end_month.set(today.month)
        values=tuple(range(1,13))
        end_month_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_month,values=values)
        end_month_cb.grid(column=2,row=1,padx=[40,0],pady=[10,0],sticky='we')
        self.end_day = tk.IntVar();self.end_day.set(today.day)
        values=lambda:list(range(1,rangeM(self.end_year.get(),self.end_month.get())[1]+1))
        end_day_cb=tkinter.ttk.Combobox(frame,textvariable=self.end_day,values=values())
        end_day_cb.grid(column=3,row=1,padx=[40,0],pady=[10,0],sticky='we')
        start_year_cb.bind(
            '<<ComboboxSelected>>', 
            lambda event:(
                start_day_cb.config({"values":list(range(1,rangeM(
                    self.start_year.get(),self.start_month.get())[1]+1))}),
                start_day_cb.current(0)
            )
        )
        start_month_cb.bind(
            '<<ComboboxSelected>>',
            lambda event:(
                start_day_cb.config({"values":list(range(1,rangeM(
                    self.start_year.get(),self.start_month.get())[1]+1))}),
                start_day_cb.current(0)
            )
        )
        end_year_cb.bind(
            '<<ComboboxSelected>>', 
            lambda event:(
                end_day_cb.config({"values":list(range(1,rangeM(
                    self.end_year.get(),self.end_month.get())[1]+1))}),
                end_day_cb.current(rangeM(
                    self.end_year.get(),self.end_month.get())[1]-1)
            )
        )
        end_month_cb.bind(
            '<<ComboboxSelected>>',
            lambda event:(
                end_day_cb.config({"values":list(range(1,rangeM(
                    self.end_year.get(),self.end_month.get())[1]+1))}),
                end_day_cb.current(rangeM(
                    self.end_year.get(),self.end_month.get())[1]-1)
            )
        )
        return

    def cloud_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置最大云量',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.max_clound = tk.IntVar();self.max_clound.set(self.params['clouds'])
        label_text=tk.StringVar();label_text.set(f'{self.max_clound.get()}%最大云量')
        tkinter.ttk.Scale(
            frame,variable=self.max_clound,from_=0,to=100,orient=tk.HORIZONTAL,length=600,
            command=lambda event:label_text.set(f'{self.max_clound.get()}%最大云量')
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,textvariable=label_text,style='b.TLabel'
        ).grid(column=2,row=0,sticky='we')
        return

    def server_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置远程连接',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')

        self.hostname = tk.StringVar();self.hostname.set('')
        values=list(self.params['ip'].keys())
        combobox=tkinter.ttk.Combobox(frame,width=13,textvariable=self.hostname,values=values) 
        combobox.grid(column=0,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,text="主机",style='b.TLabel'
        ).grid(column=1,row=0,sticky='we')
        combobox.current(0)

        self.port = tk.StringVar();self.port.set('')
        tkinter.ttk.Entry(frame,width=4,textvariable=self.port
        ).grid(column=2,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,text="端口",style='b.TLabel'
        ).grid(column=3,row=0,sticky='we')

        self.username = tk.StringVar()
        self.username.set(self.params['ip'][self.hostname.get()]['username'])
        tkinter.ttk.Entry(frame,textvariable=self.username
        ).grid(column=4,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,text="用户",style='b.TLabel'
        ).grid(column=5,row=0,sticky='we')

        self.password = tk.StringVar()
        self.password.set(self.params['ip'][self.hostname.get()]['password'])
        tkinter.ttk.Entry(frame,textvariable=self.password,show='*'
        ).grid(column=6,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,text="密码",style='b.TLabel'
        ).grid(column=7,row=0,sticky='we')

        button = tkinter.ttk.Button(frame,text="选择/连接",style='a.TButton')
        button.grid(column=0,row=1,padx=[10,0],pady=[10,0],sticky='we')

        self.folder = tk.StringVar();self.folder.set(self.params['folder'])
        tkinter.ttk.Entry(frame,width=80,textvariable=self.folder
        ).grid(column=1,row=1,columnspan=7,padx=[10,0],pady=[10,0],sticky='we')

        def button_cmd():
            if self.hostname.get() == "local host":
                folder = askdirectory(initialdir=r"E:\Image2")#self.params['folder']
                folder = folder.replace('/','\\')
                self.folder.set(folder)
             
            else:
                tk.messagebox.showinfo(
                    '温馨提示',
                    sftp_test_folder(
                        self.hostname.get(),
                        self.port.get(),
                        self.username.get(),
                        self.password.get(),
                        [self.folder.get()]
                    )
                )
            return
        button.configure(command=button_cmd)
        
        def get_params(event):
            if self.hostname.get() == "locat host":self.port.set('')
            else: self.port.set('22')
            self.username.set(self.params['ip'][self.hostname.get()]['username'])
            self.password.set(self.params['ip'][self.hostname.get()]['password'])
            return
        combobox.bind('<<ComboboxSelected>>',get_params)
        return

    def task_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='监视任务进度',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.start_button=tkinter.ttk.Button(
            frame,text="开始任务",style='a.TButton',
            command=lambda:Thread(target=self.running,args=(),daemon=True).start())
        self.start_button.grid(column=0,row=0,padx=[10,0],sticky='we')
        self.progressbar = tkinter.ttk.Progressbar(
            frame,length=600,value=0,mode="indeterminate",orient=tk.HORIZONTAL)  # mode="determinate",
        self.progressbar.grid(column=1,row=0,padx=[10,0],sticky='we') 
        self.scrolled_text = scrolledtext.ScrolledText(
            frame,height=31,state='normal',wrap = tk.WORD,font="TkFixedFont") 
        self.scrolled_text.tag_config('INFO', foreground='black')
        self.scrolled_text.tag_config('DEBUG', foreground='gray')
        self.scrolled_text.tag_config('WARNING', foreground='orange')
        self.scrolled_text.tag_config('ERROR', foreground='red')
        self.scrolled_text.tag_config('CRITICAL', foreground='red', underline=1)
        self.scrolled_text.grid(column=0,row=1,columnspan=2,padx=[10,0],pady=[10,0],sticky='we')
        return

    def running(self):

        self.progressbar.start()
        self.start_button.configure(state=tk.DISABLED)
        self.scrolled_text.configure(state=tk.NORMAL)
        self.scrolled_text.delete(0.0, tkinter.END)

        def waring_end(info):
            self.start_button.config({"state":tk.NORMAL})
            self.scrolled_text.configure(state=tk.DISABLED)
            self.progressbar.stop()
            tk.messagebox.showwarning('Waring', info)
            return

        def print_line(temp):
            temp = f"{datetime.datetime.now().strftime('%H:%M:%S')}>{temp}\n"
            self.scrolled_text.insert(tk.END,temp)
            self.scrolled_text.see(tk.END)
            self.scrolled_text.focus()
            return

        try:
            self.start_date = datetime.date(
                self.start_year.get(),self.start_month.get(),self.start_day.get())
            self.end_date = datetime.date(
                self.end_year.get(),self.end_month.get(),self.end_day.get())
        except: return waring_end('日期选择错误！')
        if self.tiles_str.get() == '请输入图幅（例如：51RTH-51RUH）':self.tiles_str.set('')
        elif self.tiles_str.get() == "" :self.tiles_str.set('')
        elif self.province.get() == "请选择省份（可选）" :self.province.set('')
        elif self.start_date > self.end_date:return waring_end('日期选择错误！')

        else:
            print_line(f"下载图幅：{self.tiles_str.get().split('-')}")
            print_line(f"下载时期：{self.start_date}--->{self.end_date}")
            print_line(f"下载时期：{self.province.get()}")
            print_line(f"最大含云量：{self.max_clound.get()}%")
        
        
        args=[
            self.hostname.get(),
            self.port.get(),
            self.username.get(),
            self.password.get(),
            self.folder.get(),
            self.tiles_str.get().split('-'),
            self.start_date.strftime("%Y-%m-%d"),
            self.end_date.strftime("%Y-%m-%d"),
            self.max_clound.get(),
        ]
        data = cs.main(*args)

        self.start_date.strftime("%Y-%m-%d")
        self.end_date.strftime("%Y-%m-%d")
        dates = []
        temp_date = self.start_date
        while temp_date <= self.end_date:
            dates.append(temp_date.strftime("%Y%m%d"))
            temp_date=temp_date +datetime.timedelta(days=1)
        columns = dates
        idname = "图幅"
        ids = self.tiles_str.get().split('-')
        SetTable(self.window,idname,ids,columns,data)

        self.start_button.config({"state":tk.NORMAL})
        self.scrolled_text.configure(state=tk.DISABLED)
        self.progressbar.stop()
        tk.messagebox.showinfo('温馨提示','任务完成！')
        return


class SetTable:

    width,height=1400,1000

    def __init__(self,master,idname,ids,columns,data) -> None:
        self.master=master
        self.columns=columns
        self.data=data
        self.idname=idname
        self.ids=ids
        self.set_toplevel()
        self.set_scorllbar()
        self.frame = tkinter.ttk.Frame(master=self.toplevel,width=self.width-10)#width=self.width,height=self.height
        self.frame.pack(anchor='nw')
        self.set_First_column()
        self.set_treeview()
        self.scrollbarY.bind("<MouseWheel>", self.Wheel)
        self.table1.bind("<MouseWheel>", self.Wheel)
        self.table.bind("<MouseWheel>", self.Wheel)
        pass

    def set_toplevel(self):
        self.toplevel = tk.Toplevel(self.master)
        self.toplevel.title('查询结果') # 标题

        screenwidth = self.toplevel.winfo_screenwidth() # 屏幕宽度
        screenheight = self.toplevel.winfo_screenheight() # 屏幕高度
        x = int((screenwidth - self.width) / 2)
        y = int((screenheight - self.height) / 2)
        locat = f"{self.width}x{self.height}+{x}+{y}"
        self.toplevel.geometry(locat) # 大小以及位置
        # self.toplevel.resizable(0,0)
        
        return

    def ScrollCommand(self,*xx):#在滚动条上点击、拖动等动作
        # print(*xx)
        self.table.yview(*xx)
        self.table1.yview(*xx)
        return

    def Wheel(self,event):#鼠标滚轮动作
        # print(str(-1*(event.delta/120)))#windows系统需要除以120
        self.table.yview_scroll(int(-1*(event.delta/120)), "units")
        self.table1.yview_scroll(int(-1*(event.delta/120)), "units")
        return "break" 

    def set_scorllbar(self):

        tkinter.ttk.Style().configure("TScrollbar",activebackground='red',)
    
        self.scrollbarY = tkinter.ttk.Scrollbar(
            self.toplevel,orient='vertical',command=self.ScrollCommand)
        self.scrollbarY.pack(anchor='e',side=tk.RIGHT,fill=tk.Y)

        self.scrollbarX = tkinter.ttk.Scrollbar(self.toplevel,orient='horizontal')
        self.scrollbarX.pack(side=tk.BOTTOM,fill=tk.X)
   
        return

    def set_First_column(self):

        tkinter.ttk.Style().map("Treeview",background=[('selected','#00aaaa')],foreground=[('selected','white')])
        tkinter.ttk.Style().configure("Treeview.Heading",font=('simhei',12,''))
        tkinter.ttk.Style().configure("Treeview",rowheight=20,font=('simhei',12,'bold'))

        self.table1 = tkinter.ttk.Treeview(
            self.frame,
            height=len(self.data),
            columns=[self.idname],
            show='headings',
        )

        self.table1.tag_configure('tag_odd',background='#ffbb99',font=('simhei',12,''),foreground="black")
        self.table1.tag_configure('tag_eve',background='#99bbff',font=('simhei',12,''),foreground="black")

        self.table1.heading(self.idname, text=self.idname)
        self.table1.column(self.idname, width=50, anchor=tk.S)

        for index,record in enumerate(self.ids):
            self.table1.insert('', index=index, text='', values=record)

        for index,row in enumerate(self.table1.get_children()):
            if index%2==1:self.table1.item(row,tags='tag_odd')
            else:self.table1.item(row,tags='tag_eve')
            
        self.table1.pack(side="left",expand=tk.YES)
        return

    def set_treeview(self):
        tkinter.ttk.Style().map("Treeview",background=[('selected','#00aaaa')],foreground=[('selected','white')])
        tkinter.ttk.Style().configure("Treeview.Heading",font=('simhei',12,''))
        tkinter.ttk.Style().configure("Treeview",rowheight=20,font=('宋体',10,''))
        self.table = tkinter.ttk.Treeview(
            self.frame,
            height=len(self.data),
            columns=self.columns,
            show='headings',
            xscrollcommand=self.scrollbarX.set,
            yscrollcommand=self.scrollbarY.set,
        )
        self.scrollbarY.config(command=self.table.yview)
        self.scrollbarX.config(command=self.table.xview)
        self.table.tag_configure('tag_odd',background='#ffbb99',foreground="blue")
        self.table.tag_configure('tag_eve',background='#99bbff',foreground="blue")

        for column in self.columns: 
            self.table.heading(column, text=column)
            self.table.column(column, width=80, anchor=tk.S)
        
        for index,record in enumerate(self.data):
            self.table.insert('', index=index, text='', values=record)

        for index,row in enumerate(self.table.get_children()):
            if index%2==1:self.table.item(row,tags='tag_odd')
            else:self.table.item(row,tags='tag_eve')
            
        self.table.pack(anchor='n',expand=tk.YES)
        return


class raster3Aserve_page:

    def __init__(self,window,params):

        tkinter.ttk.Style().configure(
            'b.TLabelframe',  
            relief="ridge",
            borderwidth=4,
            background='LightBlue', # 'LightSteelBlue'
        )

        tkinter.ttk.Style().configure(
            'a.TLabel', 
            font=('黑体','10',''), 
            background='LightBlue', # 'LightSteelBlue' # Lavender
            foreground="Navy",
            bordercolor='black',
        )

        tkinter.ttk.Style().configure(
            'b.TLabel', 
            font=('黑体','10',''), 
            background='black',  # 'LightSteelBlue' PaleTurquoise LightBlue
            foreground="black",
            bordercolor='black',
        )

        tkinter.ttk.Style().configure(
            'TCheckbutton',
            background='LightBlue',
            foreground="black",
        )

        tkinter.ttk.Style().configure(
            'a.TButton', 
            font=('黑体','10',''),
            relief="raised", 
            foreground="black",  # block
            background='RoyalBlue',
            width=10,
        )

        tkinter.ttk.Style().configure(
            'TFrame', 
            font=('黑体','16',''), 
            fg='red',
            background='Azure',
        )

        tkinter.ttk.Style().configure(
            'Horizontal.TScale', 
            background='LightSteelBlue',
        )

        self.frame = tkinter.ttk.Frame(window)
        self.params = params
        line_iter = iter(range(50)) 
        self.province_frame(self.frame,next(line_iter))
        self.period_frame(self.frame,next(line_iter))  # 时期选择
        self.bands_frame(self.frame,next(line_iter))  # 波段选择
        self.server_frame(self.frame,next(line_iter))  # 设置ssh连接
        self.file_frame(self.frame,next(line_iter))    # 设置运行文件
        self.folder_frame(self.frame,next(line_iter))  # 输入输出目录
        self.monitor_frame(self.frame,next(line_iter))  #  开启下载任务
        return

    def province_frame(self,master,row):
        frame = tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='选择行政区划',style='a.TLabel')) #  style='b.TLabelframe',
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')
        
        file_path = r".\addr.json"  # ceshi 
        self.province_file = tk.StringVar();self.province_file.set(file_path)

        tkinter.ttk.Entry(frame,width=85,textvariable=self.province_file
        ).grid(column=0,row=0,columnspan=3,padx=[10,0],sticky='we')
        tkinter.ttk.Button(
            frame,text="选择文件",style='a.TButton',
            command=lambda:self.province_file.set(tkfan().replace('/','\\'))
        ).grid(column=3,row=0,padx=[10,0],sticky='we')

        with open(self.province_file.get(),"r",encoding='utf-8') as json_file:
            context_dict = json.load(json_file)

        self.province=tk.StringVar();self.province.set('请选择省份')
        province_combobox=tkinter.ttk.Combobox(
            frame,textvariable=self.province,state='readonly',values=list(context_dict.keys())) 
        province_combobox.grid(column=0,row=1,padx=(10,0),pady=(5,0),sticky='we')

        # tkinter.ttk.Label(frame,text="省份",style='b.TLabel'
        # ).grid(column=1,row=1,padx=(0,0),pady=(0,0),sticky='we')

        self.province_code = tk.StringVar();self.province_code.set('**')
        label_text=tk.StringVar();label_text.set(f'**区划代码**')
        tkinter.ttk.Label(frame,textvariable=label_text,style='b.TLabel'
        ).grid(column=1,row=1,padx=(80,0),pady=(5,0),sticky='we')

        province_combobox.bind(
            '<<ComboboxSelected>>', 
            lambda event:(
                self.province_code.set(context_dict[self.province.get()]['code']),
                label_text.set(f'{self.province.get()}区划代码{self.province_code.get()}'),
                )
            )
        return

    def period_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='选择影像日期',style='a.TLabel'))
        frame.grid(column=0,row=row,padx=(10,0),pady=(5,0),sticky='we')

        self.year = tk.IntVar();self.year.set(datetime.date.today().year)
        tkinter.ttk.Combobox(frame,textvariable=self.year,values=self.params['years']
        ).grid(column=0,row=0,padx=(10,0),pady=[0,0],sticky='we')

        tkinter.ttk.Label(frame,text="年份",style='b.TLabel').grid(column=1,row=0,sticky='we')

        self.month = tk.IntVar();self.month.set(datetime.date.today().month)
        tkinter.ttk.Combobox(frame,textvariable=self.month,values=tuple(range(1,13))
        ).grid(column=2,row=0,padx=[40,0],pady=[0,0],sticky='we')

        tkinter.ttk.Label(frame,text="月份",style='b.TLabel').grid(column=3,row=0,sticky='we')

        self.interval = tk.StringVar();self.interval.set("3000")
        tkinter.ttk.Combobox(frame,textvariable=self.interval,values=("1501","1502","3000")
        ).grid(column=4,row=0,padx=[40,0],pady=[0,0],sticky='we')

        tkinter.ttk.Label(frame,text="时期类型",style='b.TLabel').grid(column=5,row=0,sticky='we')
        return

    def bands_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='选择合成波段',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')

        self.values  = []
        for band in self.params['bands']:
            exec(f"self.B{band}=tk.StringVar()")
            if band!='99':exec(f"self.B{band}.set('{band}')")
            else: exec(f"self.B{band}.set('')")
            exec(f"self.values.append(self.B{band})")
            
        self.bandsstr=tk.StringVar()
        self.bandsstr.set("-".join(self.params['bands'][:9]))

        for index, band in enumerate(self.params['bands']):
            if index == 0:
                checkbutton = tkinter.ttk.Checkbutton(
                    frame,text=f"{band} Band",onvalue=band,offvalue='',variable=self.values[index],
                    # command=lambda:(self.bands.append([i.get()for i in self.values]),print([i.get()for i in self.values]))
                    # command=lambda:self.scrolledT.insert(tk.END,'-'.join([i.get()for i in self.values if i.get()!=''])+'\n'),
                    command=lambda:self.bandsstr.set('-'.join([i.get()for i in self.values if i.get()!=''])),
                )
                checkbutton.grid(column=index,row=0,padx=(10,0),pady=(0,0),sticky='we')
            elif index < 6 and index != 0:
                checkbutton=tkinter.ttk.Checkbutton(
                    frame,text=f"{band} Band",onvalue=band,offvalue='',variable=self.values[index],
                    # command=lambda:self.scrolledT.insert(tk.END,'-'.join([i.get()for i in self.values if i.get()!=''])+'\n') 
                    command=lambda:self.bandsstr.set('-'.join([i.get()for i in self.values if i.get()!=''])),
                )
                checkbutton.grid(column=index,row=0,padx=(50,0),pady=(0,0),sticky='we')
            elif index ==6:  
                checkbutton=tkinter.ttk.Checkbutton(
                    frame,text=f"{band} Band",onvalue=band,offvalue='',variable=self.values[index],
                    # command=lambda:self.scrolledT.insert(tk.END,'-'.join([i.get()for i in self.values if i.get()!=''])+'\n')
                    command=lambda:self.bandsstr.set('-'.join([i.get()for i in self.values if i.get()!=''])),
                )
                checkbutton.grid(column=index-6,row=1,padx=(10,0),pady=(10,0),sticky='we')
            else:
                checkbutton=tkinter.ttk.Checkbutton(
                    frame,text=f"{band} Band",onvalue=band,offvalue='',variable=self.values[index],
                    # command=lambda:self.scrolledT.insert(tk.END,'-'.join([i.get()for i in self.values if i.get()!=''])+'\n')
                    command=lambda:self.bandsstr.set('-'.join([i.get()for i in self.values if i.get()!=''])),
                )
                checkbutton.grid(column=index-6,row=1,padx=(50,0),pady=(10,0),sticky='we')

        return

    def server_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置远程连接',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')

        self.hostname = tk.StringVar();self.hostname.set(self.params['sshargs']['ip'])
        tkinter.ttk.Entry(frame,width=13,textvariable=self.hostname).grid(column=0,row=0,padx=[10,0],sticky='we')
        tkinter.ttk.Label(frame,text="主机",style='b.TLabel').grid(column=1,row=0,sticky='we')

        self.port = tk.StringVar();self.port.set(self.params['sshargs']['port'])
        tkinter.ttk.Entry(frame,width=4,textvariable=self.port).grid(column=2,row=0,padx=[15,0],sticky='we')
        tkinter.ttk.Label(frame,text="端口",style='b.TLabel').grid(column=3,row=0,sticky='we')

        self.username = tk.StringVar();self.username.set(self.params['sshargs']['username'])
        tkinter.ttk.Entry(frame,textvariable=self.username).grid(column=4,row=0,padx=[15,0],sticky='we')
        tkinter.ttk.Label(frame,text="用户",style='b.TLabel').grid(column=5,row=0,sticky='we')

        self.password = tk.StringVar();self.password.set(self.params['sshargs']['password'])
        tkinter.ttk.Entry(frame,textvariable=self.password,show='*').grid(column=6,row=0,padx=[15,0],sticky='we')
        tkinter.ttk.Label(frame,text="密码",style='b.TLabel').grid(column=7,row=0,sticky='we')


        self.textlink_button = tkinter.ttk.Button(
            frame,text="测试连接",style='a.TButton',
            command=lambda:tk.messagebox.showinfo(
                '温馨提示',
                ssh_test(self.hostname.get(),self.port.get(),self.username.get(),self.password.get())
            )
        )
        self.textlink_button.grid(column=8,row=0,padx=[15,0],pady=[0,0],sticky='we')
        return

    def folder_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='输入输出目录',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')

        self.gykm_dir = tk.StringVar();self.gykm_dir.set(self.params["gykm_dir"])
        tkinter.ttk.Entry(frame,width=85,textvariable=self.gykm_dir
        ).grid(column=0, row=0, padx=[10,0], pady=(0,0), sticky='we')

        self.base_dir = tk.StringVar();self.base_dir.set(self.params["base_dir"])
        tkinter.ttk.Entry(frame,width=85,textvariable=self.base_dir
        ).grid(column=0, row=1, padx=[10,0], pady=(10,0), sticky='we')

        tkinter.ttk.Button(
            frame,text="测试目录",style='a.TButton',
            command=lambda:tk.messagebox.showinfo(
                "温馨提示：",sftp_test_folder(
                    self.hostname.get(),
                    self.port.get(),
                    self.username.get(),
                    self.password.get(),
                    [self.gykm_dir.get(),self.base_dir.get()]
                )
            )
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        return

    def file_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='设置运行文件',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')

        self.python_path = tk.StringVar();self.python_path.set(self.params["python_path"])
        tkinter.ttk.Entry(frame,width=85,textvariable=self.python_path
        ).grid(column=0, row=0, padx=[10,0], pady=(0,0), sticky='we')

        self.script_path = tk.StringVar();self.script_path.set(self.params["script_path"])
        tkinter.ttk.Entry(frame,width=85,textvariable=self.script_path
        ).grid(column=0, row=1, padx=[10,0], pady=(10,0), sticky='we')

        tkinter.ttk.Button(
            frame,text="测试文件",style='a.TButton',
            command=lambda:tk.messagebox.showinfo(
                "温馨提示：",sftp_test_file(
                    self.hostname.get(),
                    self.port.get(),
                    self.username.get(),
                    self.password.get(),
                    [self.python_path.get(),self.script_path.get()]
                )
            )
        ).grid(column=1,row=0,padx=[10,0],sticky='we')
        return

    def monitor_frame(self,master,row):
        frame= tkinter.ttk.LabelFrame(master,style='b.TLabelframe',
            labelwidget=tkinter.ttk.Label(text='监视任务进度',style='a.TLabel'))
        frame.grid(column=0, row=row, padx=(10,0), pady=(5,0), sticky='we')
        self.start_button=tkinter.ttk.Button(
            frame,text="开始任务",style='a.TButton',
            command=lambda:Thread(target=self.running,args=(),daemon=True).start())
        self.start_button.grid(column=0,row=0,padx=[10,0],sticky='we')
        self.progressbar = tkinter.ttk.Progressbar(
            frame,length=600,value=0,mode="indeterminate",orient=tk.HORIZONTAL)  # mode="determinate",
        self.progressbar.grid(column=1,row=0,padx=[10,0],sticky='we') 
        self.scrolledT = scrolledtext.ScrolledText(
            frame,height=21,state='normal',wrap = tk.WORD,font="TkFixedFont") 
        self.scrolledT.tag_config('INFO', foreground='black')
        self.scrolledT.tag_config('DEBUG', foreground='gray')
        self.scrolledT.tag_config('WARNING', foreground='orange')
        self.scrolledT.tag_config('ERROR', foreground='red')
        self.scrolledT.tag_config('CRITICAL', foreground='red', underline=1)
        self.scrolledT.grid(column=0,row=1,columnspan=2,padx=[10,0],pady=[10,0],sticky='we')
        return

    def running(self):
        self.progressbar.start()
        self.start_button.configure(state=tk.DISABLED)
        self.scrolledT.configure(state=tk.NORMAL)
        self.scrolledT.delete(0.0, tkinter.END)

        def waring_end(info):
            self.start_button.config({"state":tk.NORMAL})
            self.scrolledT.configure(state=tk.DISABLED)
            self.progressbar.stop()
            tk.messagebox.showwarning('Waring', info)
            return

        def print_line(temp):
            temp = f"{datetime.datetime.now().strftime('%H:%M:%S')}>{temp}\n"
            self.scrolledT.insert(tk.END,temp)
            self.scrolledT.see(tk.END)
            self.scrolledT.focus()
            return

        if self.province.get() == "请选择省份": return waring_end('没有选择省份！')
        elif self.bandsstr.get() == '' : return waring_end('没有选择波段！')
        else:
            print_line(f"选择省份：{self.province.get()},{self.province_code.get()}")
            print_line(f"设置时期：{self.year.get()},{self.month.get()},{self.interval.get()}")
            print_line(f"选择波段：{self.bandsstr.get()}")
            print_line(f"远程输入目录：{self.gykm_dir.get()}")
            print_line(f"远程输出目录：{self.base_dir.get()}")
            print_line(f"python路径：{self.python_path.get()}")
            print_line(f"script路径：{self.script_path.get()}")
        params = [
            f"{self.python_path.get()}",
            f"{self.script_path.get()}",
            f"--province {self.province.get()}",
            f"--province_code {self.province_code.get()}",
            f"--year {self.year.get()}",
            f"--month {self.month.get()}",
            f"--period {self.interval.get()}",
            f"--bands {self.bandsstr.get()}",
            f"--gykm_dir {self.gykm_dir.get()}",
            f"--base_dir {self.base_dir.get()}"
        ]
        command = " ".join(params)
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
        ssh.connect(
            hostname=self.hostname.get(),
            port=self.port.get(),
            username=self.username.get(),
            password=self.password.get()
        )
        _,stdout,_ = ssh.exec_command(command,get_pty=True)
        for line in iter(stdout.readline,""): 
            print_line(line)
        ssh.close()
        self.start_button.config({"state":tk.NORMAL})
        self.scrolledT.configure(state=tk.DISABLED)
        self.progressbar.stop()
        tk.messagebox.showinfo('温馨提示','任务完成！')
        return


if __name__ == "__main__":
    command=r"net use Z: \\192.168.2.172\root DELL123dell /user:root"
    try:
        os.system(command)
    except:
        pass
    UI()


   
    
